Closed Xeckt closed 4 months ago
make sense, @Xeckt go for it!
couple more things that could help:
status
command has wrong argumentsrun
and daemon
should do exactly the same, but daemon in the loop and run only onceCool, I'll get started!
couple more things that could help:
status
command has wrong argumentsrun
anddaemon
should do exactly the same, but daemon in the loop and run only once
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 status
with much more details here #399
daemon
like today can take over the session but in loop until success
run
is like daemon
but exits after one iteration with success or fail
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:Flags: -h, --help help for systemd -o, --options string sztp-agent args/flags to add into the unit file -p, --path string Path for unit file to be created (default "/etc/systemd/system")
2024/06/24 16:06:34 [ERROR] creating unit file /etc/systemd/system/sztp-agent.service: open /etc/systemd/system/sztp-agent.service: permission denied
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.