Skip to content

Commit

Permalink
change interface of resolveConfigForRetire and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Feb 20, 2016
1 parent e12beeb commit e75bb85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
5 changes: 4 additions & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func doConfigtest(fs *flag.FlagSet, argv []string) error {
retire the host
*/
func doRetire(fs *flag.FlagSet, argv []string) error {
conf, force := resolveConfigForRetire(fs, argv)
conf, force, err := resolveConfigForRetire(fs, argv)
if err != nil {
return fmt.Errorf("failed to load config: %s", err)
}

hostID, err := conf.LoadHostID()
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,11 @@ func printRetireUsage() {
os.Exit(2)
}

func resolveConfigForRetire(fs *flag.FlagSet, argv []string) (*config.Config, bool) {
func resolveConfigForRetire(fs *flag.FlagSet, argv []string) (*config.Config, bool, error) {
var force = fs.Bool("force", false, "force retirement without prompting")
fs.Usage = printRetireUsage
conf, err := resolveConfig(fs, argv)
if err != nil {
logger.Criticalf("failed to load config: %s", err)
printRetireUsage()
}
return conf, *force
return conf, *force, err
}

// resolveConfig parses command line arguments and loads config file to
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestDetectForce(t *testing.T) {
defer os.Remove(confFile.Name())

argv := []string{"-conf=" + confFile.Name()}
conf, force := resolveConfigForRetire(&flag.FlagSet{}, argv)
conf, force, err := resolveConfigForRetire(&flag.FlagSet{}, argv)
if force {
t.Errorf("force should be false")
}
Expand All @@ -80,7 +80,7 @@ func TestDetectForce(t *testing.T) {
}

argv = append(argv, "-force")
conf, force = resolveConfigForRetire(&flag.FlagSet{}, argv)
conf, force, err = resolveConfigForRetire(&flag.FlagSet{}, argv)
if !force {
t.Errorf("force should be true")
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestResolveConfigForRetire(t *testing.T) {
"-role=hoge:fuga",
}

conf, force := resolveConfigForRetire(&flag.FlagSet{}, argv)
conf, force, err := resolveConfigForRetire(&flag.FlagSet{}, argv)
if force {
t.Errorf("force should be false")
}
Expand Down

0 comments on commit e75bb85

Please sign in to comment.