From f70fb153c4ec28fcf3cc3783c3c61f0dbfbb588d Mon Sep 17 00:00:00 2001 From: wuqixuan Date: Sun, 17 May 2015 22:29:58 +0800 Subject: [PATCH 1/2] fleetctl: Add the args check for some subcommand Some subcommand like destroy/load/start/status/stop/submit/unload, need to give prompt if no args for them. Add the same prompt "One unit file must be provided" as the "cat" subcommand is doing: [root@localhost fleet-0.10.1]# fleetctl cat One unit file must be provided --- fleetctl/destroy.go | 4 ++++ fleetctl/load.go | 4 ++++ fleetctl/start.go | 4 ++++ fleetctl/status.go | 4 ++++ fleetctl/stop.go | 4 ++++ fleetctl/submit.go | 4 ++++ fleetctl/unload.go | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/fleetctl/destroy.go b/fleetctl/destroy.go index d00778aa1..86b8d5f01 100644 --- a/fleetctl/destroy.go +++ b/fleetctl/destroy.go @@ -29,6 +29,10 @@ Destroyed units are impossible to start unless re-submitted.`, } func runDestroyUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } for _, v := range args { name := unitNameMangle(v) err := cAPI.DestroyUnit(name) diff --git a/fleetctl/load.go b/fleetctl/load.go index 497f86058..fb801ea77 100644 --- a/fleetctl/load.go +++ b/fleetctl/load.go @@ -46,6 +46,10 @@ func init() { } func runLoadUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) return 1 diff --git a/fleetctl/start.go b/fleetctl/start.go index 77ea0d343..203dd9a8a 100644 --- a/fleetctl/start.go +++ b/fleetctl/start.go @@ -54,6 +54,10 @@ func init() { } func runStartUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) return 1 diff --git a/fleetctl/status.go b/fleetctl/status.go index c1b065f1b..aa89625ee 100644 --- a/fleetctl/status.go +++ b/fleetctl/status.go @@ -44,6 +44,10 @@ func init() { } func runStatusUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } units, err := cAPI.Units() if err != nil { stderr("Error retrieving unit: %v", err) diff --git a/fleetctl/stop.go b/fleetctl/stop.go index 262946bfb..4de3fd885 100644 --- a/fleetctl/stop.go +++ b/fleetctl/stop.go @@ -52,6 +52,10 @@ func init() { } func runStopUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } units, err := findUnits(args) if err != nil { stderr("%v", err) diff --git a/fleetctl/submit.go b/fleetctl/submit.go index cbfe03f93..767078817 100644 --- a/fleetctl/submit.go +++ b/fleetctl/submit.go @@ -36,6 +36,10 @@ func init() { } func runSubmitUnits(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } if err := lazyCreateUnits(args); err != nil { stderr("Error creating units: %v", err) exit = 1 diff --git a/fleetctl/unload.go b/fleetctl/unload.go index 6758f2825..d2d0245e9 100644 --- a/fleetctl/unload.go +++ b/fleetctl/unload.go @@ -36,6 +36,10 @@ func init() { } func runUnloadUnit(args []string) (exit int) { + if len(args) == 0 { + stderr("One unit file must be provided.") + return 1 + } units, err := findUnits(args) if err != nil { stderr("%v", err) From 810b59c8907a998689d15d2c07b069ecdd65d3e4 Mon Sep 17 00:00:00 2001 From: wuqixuan Date: Mon, 18 May 2015 00:23:27 +0800 Subject: [PATCH 2/2] fleetctl: stop subcommand return fail if not correct args --- fleetctl/stop.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fleetctl/stop.go b/fleetctl/stop.go index 4de3fd885..94b85668d 100644 --- a/fleetctl/stop.go +++ b/fleetctl/stop.go @@ -56,12 +56,18 @@ func runStopUnit(args []string) (exit int) { stderr("One unit file must be provided.") return 1 } + units, err := findUnits(args) if err != nil { stderr("%v", err) return 1 } + if len(units) == 0 { + stderr("The units to be stopped are not found in registry.") + return 1 + } + stopping := make([]string, 0) for _, u := range units { if !suToGlobal(u) {