Added validation for argument in start/stop app command. Colorized error output on validation fail
parent
9ccb3f1d71
commit
a44c44baa8
|
@ -11,12 +11,16 @@ import (
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/tasks"
|
"github.com/edgebox-iot/edgeboxctl/internal/tasks"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||||
"github.com/urfave/cli/v2" // imports as package "cli"
|
"github.com/mitchellh/colorstring"
|
||||||
|
"github.com/urfave/cli/v2" // imports as package "cli",
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultNotReadySleepTime time.Duration = time.Second * 60
|
const defaultNotReadySleepTime time.Duration = time.Second * 60
|
||||||
const defaultSleepTime time.Duration = time.Second
|
const defaultSleepTime time.Duration = time.Second
|
||||||
|
|
||||||
|
var errorMissingApplicationSlug = colorstring.Color("[red]Error: [white]Missing application slug")
|
||||||
|
var errorUnexpected = colorstring.Color("[red]An unexpected error ocurring and the application crashed")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
|
@ -29,7 +33,7 @@ func main() {
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "bootstrap",
|
Name: "bootstrap",
|
||||||
Aliases: []string{"a"},
|
Aliases: []string{"b"},
|
||||||
Usage: "Setps up initial structure and dependencies for the edgebox system",
|
Usage: "Setps up initial structure and dependencies for the edgebox system",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
fmt.Println("Edgebox Setup")
|
fmt.Println("Edgebox Setup")
|
||||||
|
@ -38,13 +42,19 @@ func main() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "app",
|
Name: "app",
|
||||||
Aliases: []string{"t"},
|
Aliases: []string{"a"},
|
||||||
Usage: "options for edgeapp management",
|
Usage: "options for edgeapp management",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
{
|
{
|
||||||
Name: "start",
|
Name: "start",
|
||||||
Usage: "start the specified app",
|
Aliases: []string{"s"},
|
||||||
|
Usage: "start the specified app",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
|
||||||
|
if c.Args().Get(0) == "" {
|
||||||
|
return cli.Exit(errorMissingApplicationSlug, 1)
|
||||||
|
}
|
||||||
|
|
||||||
task := tasks.ExecuteTask(tasks.GetBaseTask(
|
task := tasks.ExecuteTask(tasks.GetBaseTask(
|
||||||
"start_edgeapp",
|
"start_edgeapp",
|
||||||
fmt.Sprintf("{\"id\": \"%s\"}", c.Args().First()),
|
fmt.Sprintf("{\"id\": \"%s\"}", c.Args().First()),
|
||||||
|
@ -58,6 +68,10 @@ func main() {
|
||||||
Usage: "stop the specified app",
|
Usage: "stop the specified app",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
|
||||||
|
if c.Args().Get(0) == "" {
|
||||||
|
return cli.Exit(errorMissingApplicationSlug, 1)
|
||||||
|
}
|
||||||
|
|
||||||
task := tasks.ExecuteTask(tasks.GetBaseTask(
|
task := tasks.ExecuteTask(tasks.GetBaseTask(
|
||||||
"stop_edgeapp",
|
"stop_edgeapp",
|
||||||
fmt.Sprintf("{\"id\": \"%s\"}", c.Args().First()),
|
fmt.Sprintf("{\"id\": \"%s\"}", c.Args().First()),
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -13,6 +13,7 @@ require (
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||||
github.com/urfave/cli/v2 v2.3.0 // indirect
|
github.com/urfave/cli/v2 v2.3.0 // indirect
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -32,6 +32,8 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
|
||||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
||||||
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
|
||||||
|
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
|
|
Loading…
Reference in New Issue