Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Cli multiple clusters #859

Merged
merged 1 commit into from Feb 25, 2015
Merged

Cli multiple clusters #859

merged 1 commit into from Feb 25, 2015

Conversation

geovanisouza92
Copy link
Contributor

Solves #190

func runClusterDefault(args *docopt.Args) error {
name := args.String["<cluster-name>"]

if config.SetDefault(name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Flip the conditional, so that we avoid indenting code:

if !config.SetDefault(name) {
   return nil
}

if err := config.SaveTo(configPath()); err != nil {
   return err
}
...

@archseer
Copy link
Contributor

Nice work! I'd say we need a few integration tests (see test/test_cli.go) for the new behaviour.

@@ -39,7 +40,7 @@ func (c *Config) Marshal() []byte {
return buf.Bytes()
}

func (c *Config) Add(s *Cluster) error {
func (c *Config) Add(s *Cluster, force bool, set_as_default bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

default or setDefault (Golang uses camel case)

@geovanisouza92
Copy link
Contributor Author

@archseer This seems weird. The recent build reports that Config.Default is not set. Maybe you can give a look and see what I don't see?

@archseer
Copy link
Contributor

archseer commented Feb 4, 2015

The test failure is a bug in the TOML decoding library, the Default key is printed right after the [[cluster]], and then parsed incorrectly. Switching these two lines, so that Default is first fixes it, I'll also try updating the library itself.

if err := config.Add(s); err != nil {
f := args.Bool["--force"]
d := args.Bool["--default"]
if err := config.Add(s, f, d); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of passing the default flag into config.Add, I'd call config.SetDefault right after calling config.Add:

if err := config.Add(s, args.Bool["--force"]); err != nil {
  return err
}
if args.Bool["--default"] {
  if err := config.SetDefault(s.Name); err != nil {
    return err
  }
}

@archseer
Copy link
Contributor

archseer commented Feb 4, 2015

Yes, the TOML bug is fixed on the latest version, so wait until #957 is merged, then rebase on master.

@archseer
Copy link
Contributor

archseer commented Feb 4, 2015

Also, it'd be good to know which cluster is the default, so flynn cluster default should print out the current default, and maybe flynn cluster could print a (default) at the end of the row for the default cluster. Other than that, seems to work fine :)

@archseer archseer closed this in #957 Feb 4, 2015
@archseer archseer reopened this Feb 4, 2015
@geovanisouza92
Copy link
Contributor Author

Finally green! 😄

@archseer
Copy link
Contributor

archseer commented Feb 5, 2015

@geovanisouza92 Great, can you squash these up into a single commit? :)

/cc @flynn/devs for a review

remove removes a cluster from the ~/.flynnrc configuration file
add adds a cluster to the ~/.flynnrc configuration file
remove removes a cluster from the ~/.flynnrc configuration file
default set the default cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

set or print the default cluster

@titanous
Copy link
Contributor

This looks good! It can be merged after my minor comments are addressed and rebased on top of master.

@geovanisouza92
Copy link
Contributor Author

@titanous RFC ✨


// Remove existing match
c.Clusters = append(c.Clusters[:i], c.Clusters[i+1:]...)
msg = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to do this anymore.

@archseer
Copy link
Contributor

@geovanisouza92 One last change, then we merge! :)

cli: Adding "force" flag to override cluster config
cli: Adding cluster "default" flag and command
cli: Remove cluster from config when --force
cli: Use default cluster from ~/.flynnrc
cli: Renaming parameters
cli: Test global cluster flag
cli: Test force flag to replace config
cli: Test change default cluster
cli: Testing default cluster config
cli: Remove if-else-if
cli: Add default cluster emits message
cli: Swap lines to avoid toml decoding issue
cli: Simplify set default cluster
cli: Show default cluster in list
cli: Set first cluster as default
cli: Enhance message when cluster does not exist
cli: Scoping message on Config.Add()

Signed-off-by: Geovani de Souza <geovanisouza92@gmail.com>
@geovanisouza92
Copy link
Contributor Author

Code changed, rebased on master, but fails on test_deployer.go:175, apparently nothing related to PR.

Anyway, considering that this is my 2nd Go code, I think that's awesome, thanks for you patience and guidance! 😄

@titanous
Copy link
Contributor

LGTM, thanks! (I restarted the CI build)

titanous added a commit that referenced this pull request Feb 25, 2015
@titanous titanous merged commit a7a27d8 into flynn:master Feb 25, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants