-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement easy cobra commands, fix command outputs #413
Comments
make sense, @Xeckt go for it! |
couple more things that could help:
|
Cool, I'll get started! |
Could you abbreviate more on the status command? It looks like it's templated from another command file but I suppose it's function is different. Judging by the name it reports the status, can you give me more details on that? Does the daemon need to run in the background or it can take the current session over? |
I opened separate issue for |
Ok, I will make the changes for the CLI as mentioned in this issue and make a PR, then I'll handle that issue seperately. |
At the moment, the source utilises Cobra CLI in a simple form when it comes to adding the commands to it. In the main file for the
sztp-agent
you have the following:https://github.com/opiproject/sztp/blob/33b5b5ce949c76c17786e71e9dc933443b294e15/sztp-agent/main.go#L28C1-L47C2
The individual use of
c.AddCommand(...)
can be quite cumbersome in the future where the CLI grows. So I'd like to propose a solution for this:var Commands []*cobra.Command
sliceinit()
func instead ofNewXCommand
init()
funcs for all commands append themselves to the commands sliceAdditionally, there seems to be something I think could be changed. Every time a command might fail, it runs prints the help text. I was testing it with my new command I created for generating
systemd
unit files:And it prints the error twice, same with the other commands created. In my personal experience this should only happen if the user specifically specifies
--help | -h
with a command and/or subcommand. Not upon command failure, otherwise it drowns out the real error message.I believe the structure of cobra needs some amendments and fixes to streamline it and make it cleaner. E.g.
This can be done all under
main()
, and my proposed changes to how we add commands.I'd be happy to implement this and make all the necessary changes. This way, we'd never have to do anything with the main function unless necessary, and adding commands becomes a little bit more straightforward.
The text was updated successfully, but these errors were encountered: