Skip to content

Commit

Permalink
feat(ui,api,cli): add workflow template (#3387)
Browse files Browse the repository at this point in the history
1. Description
1. Related issues
close #742
1. About tests
1. Mentions

@ovh/cds
  • Loading branch information
richardlt authored and bnjjj committed Dec 3, 2018
1 parent 8541289 commit 6518c9c
Show file tree
Hide file tree
Showing 152 changed files with 6,382 additions and 762 deletions.
44 changes: 32 additions & 12 deletions cli/ask_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func AskForConfirmation(s string) bool {
reader := bufio.NewReader(os.Stdin)

for {
fmt.Printf("%s [y/n]: ", s)
fmt.Printf("%s [Y/n]: ", s)

response, err := reader.ReadString('\n')
if err != nil {
Expand All @@ -23,38 +23,58 @@ func AskForConfirmation(s string) bool {

response = strings.ToLower(strings.TrimSpace(response))

if response == "y" || response == "yes" {
if response == "Y" || response == "y" || response == "yes" {
return true
} else if response == "n" || response == "no" {
return false
} else if response == "" {
return true
}
}
}

// MultiChoice for multiple choices question. It returns the selected option
func MultiChoice(s string, opts ...string) string {
func MultiChoice(s string, opts ...string) int {
reader := bufio.NewReader(os.Stdin)

fmt.Println(s)
if len(opts) == 0 {
log.Fatal(fmt.Errorf("no choice available"))
}
for i, o := range opts {
fmt.Printf("\t%s [%d]\n", o, (i + 1))
fmt.Printf("\t[%d] %s\n", (i + 1), o)
}

for {
fmt.Printf("Your choice [1-%d]: ", len(opts))

if len(opts) > 1 {
fmt.Printf("Your choice [1-%d]: ", len(opts))
} else {
fmt.Printf("Your choice [1]: ")
}
response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}

for i, o := range opts {
trimmedResponse := strings.TrimSpace(response)
n, _ := strconv.Atoi(trimmedResponse)
if n == i+1 {
return o
}
n, _ := strconv.Atoi(strings.TrimSpace(response))
if 0 < n && n <= len(opts) {
return n - 1
}

fmt.Println("wrong choice")
}
}

// AskValueChoice ask for a string and returns it.
func AskValueChoice(s string) string {
reader := bufio.NewReader(os.Stdin)

fmt.Printf("%s", s)

response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}

return strings.TrimSpace(response)
}
6 changes: 1 addition & 5 deletions cli/cdsctl/admin_grpc_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,7 @@ func adminPluginsAddBinaryFunc(v cli.Values) error {
return fmt.Errorf("unable to compute sha512sum for file %s: %v", v.GetString("filename"), err)
}

if err := client.PluginAddBinary(p, &desc); err != nil {
return err
}

return nil
return client.PluginAddBinary(p, &desc)
}

var adminPluginsDocCmd = cli.Command{
Expand Down
10 changes: 2 additions & 8 deletions cli/cdsctl/admin_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ func adminPlatformModelImportRun(v cli.Values) error {
//Try to load the model to know if we have to add it or update it
model, _ := client.PlatformModelGet(m.Name)
if model.ID == 0 { // If the model has not been found
if err := client.PlatformModelAdd(m); err != nil {
return err
}
return nil
return client.PlatformModelAdd(m)
}

return client.PlatformModelUpdate(m)
Expand All @@ -130,8 +127,5 @@ var adminPlatformModelDeleteCmd = cli.Command{
}

func adminPlatformModelDeleteRun(v cli.Values) error {
if err := client.PlatformModelDelete(v.GetString("name")); err != nil {
return err
}
return nil
return client.PlatformModelDelete(v.GetString("name"))
}
Loading

0 comments on commit 6518c9c

Please sign in to comment.