Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Conversation

@dongsupark
Copy link

@dongsupark dongsupark commented May 13, 2016

Use Cobra (https://github.com/spf13/cobra) instead of cli (https://github.com/codegangsta/cli), for better cmdline user interface. Create a wrapper runWrapper() to be used for cobra, to wrap around a normal run*() function into a prototype for cobra.Command.Run(). It also sets a global variable cAPI for running a normal command. Also remove unnecessary code for codegangsta/cli from fleetctl.go.

This PR consists of 6 patches.

  • 1st "fleetctl: move to cli" was taken from Move to cli #1570, though I had to modify that to get it working with the current vendor structure.
  • 2-6 are my patches.
  • The 2nd "vendor github.com/spf13/{cobra,pflag}" and 3rd "fleetctl: do not pass around cAPI" are just preparations.
  • The 4th "fleetctl: convert cli to cobra" actually covers most changes. As cobra affects nearly every fleetctl command, this is rather a huge change.
  • 5th "fleetctl: use cobra also for unit tests" and 6th "functional: run correct commands for fleetctl help" are just minor updates for unit tests as well as functional tests.

Suggested-by: @jonboulle
Fixes: #1453
Supersedes #1570

/cc @reneengelhard @kayrus @tixxdz

@dongsupark dongsupark self-assigned this May 13, 2016
@dongsupark dongsupark added this to the v0.13.0 milestone May 13, 2016
@dongsupark dongsupark force-pushed the dongsu/fleetctl-cobra-cli branch 2 times, most recently from 0e446f2 to e16d251 Compare May 14, 2016 05:35
@dongsupark dongsupark force-pushed the dongsu/fleetctl-cobra-cli branch 5 times, most recently from 9dfab96 to a7509a5 Compare May 17, 2016 08:48
fleetctl/help.go Outdated
if len(flag.Deprecated) > 0 || flag.Hidden {
return
}
format := ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really these should probably either write into the output buffer directly, or use another bytes buffer here to construct the formatting string

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure why it's written like that, as I copied the help.go from rkt. I just thought this was a common pattern. Will try to fix it.

@dongsupark dongsupark force-pushed the dongsu/fleetctl-cobra-cli branch from a7509a5 to 1d478d9 Compare May 19, 2016 14:49
@dongsupark
Copy link
Author

Updated.

  • removed fakeAPI parameters from runWrapper() and each corresponding run*() command, for simpler code. Instead, in each run*() command, determine the context by checking for a global variable cAPI. Unit tests will directly set the global cAPI to fakeAPI.
  • removed fleetFlagUsages(), and made it just directly call the native FlagUsages() method provided by spf13/pflag. This way we don't have to keep our own FlagUsages().
  • removed Get*Command() functions, and made each call just get a cmd* variable.

@dongsupark dongsupark force-pushed the dongsu/fleetctl-cobra-cli branch 2 times, most recently from 115aaef to 2f3b2e7 Compare May 19, 2016 15:57
reneengelhard and others added 6 commits May 20, 2016 10:17
- rework option parsing
- move away from (most) global variables (cAPI), keep currentCommand for now...
- we need to pass c (the cli context) and cAPI (the client API) around

Signed-off-by: Olaf Buddenhagen <[email protected]>
Add github.com/spf13/cobra and github.com/spf13/pflag.
Let's roll back to the original global variable cAPI, to keep the
entire code as simple as possible. As this is a single command-line
tool, it would be harmless to simply use a global variable.
Use Cobra (github.com/spf13/cobra) instead of cli
(github.com/codegangsta/cli), for better cmdline user interface.

* Create a wrapper runWrapper() to be used for cobra, to wrap around
  a normal run*() function into a prototype for cobra.Command.Run().
  It also sets a global variable cAPI for running a normal command.
* remove unnecessary code for codegangsta/cli from fleetctl.go.

Suggested-by: Jonathan Boulle <[email protected]>
Fixes: coreos#1453
Supersedes coreos#1570
As every fleetctl command uses cobra instead of codegangsta/cli,
we need to update unit tests as well.
* Do not compare output of help messages, to avoid occasional failures.
  As cobra sometimes prints out a different help message, it causes
  functional test TestClientHelpFlag to fail.
* Run "fleetctl version" instead of "fleetctl --version".
* Run "fleetctl help" instead of "fleetctl" to get help message.
@dongsupark dongsupark force-pushed the dongsu/fleetctl-cobra-cli branch from 2f3b2e7 to 235875e Compare May 20, 2016 08:31
@dongsupark
Copy link
Author

I managed to remove duplicated calls for setting cAPI in each command, by moving the call into runWrapper(), as @jonboulle suggested.

@dongsupark dongsupark merged commit 6f3df2e into coreos:master May 30, 2016
@dongsupark
Copy link
Author

Merged #1581.
Thanks for everyone who has been involved in this long-running issue, as well as doing extensive code reviews. If anything breaks after this, feel free to create an issue.

@dongsupark dongsupark deleted the dongsu/fleetctl-cobra-cli branch May 30, 2016 13:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants