go >= 1.17- cobra cli package:
go install github.com/spf13/cobra-cli@latest
Build the project by running: make build
In order to use cobra-cli and generate a new command, change your working path to the internal directory.
-
Create a new directory with the name of the parent command.
For example, in order to add the command
add edgedevice, create a new directory underinternal/namedadd. -
Import the new directory in the
main.gofile, by adding the next line to the import section:_ "github.com/arielireni/flotta-dev-cli/internal/cmd/<parent command name>" -
Use the cobra generator to create the new command:
cobra add <command name>This will create a new file named
<parent command name>.goinside thecmddirectory. -
Move the new file to the parent command directory.
-
Use the cobra generator to create the new command:
cobra add <sub-command name> -p '<command>Cmd'This will create a new file named
<sub-command name>.goinside thecmddirectory. -
Move the new file to the parent command directory.
-
Change
rootCmdto public by renaming it toRootCmd, so it will be importable in the<parent command name>.gofile. -
Make your own changes in the new generated file.
-
To edit parent command, edit the file
<parent command>.goin/internal/cmd/<parent command name>. -
To edit sub-command, edit the file
<sub-command name>.goin/internal/cmd/<parent command name>.
Once you have finished editing the files, re-build the project: make build.