From d104973e8462d4450cf332900fc56fb22774e962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Polovina?= Date: Wed, 17 Aug 2022 17:28:25 +0200 Subject: [PATCH] Add flag for creating non-existing projects before execution, instead of prompting the user --- README.md | 33 +++++++++++++++++---------------- cmd/execute/execute.go | 38 +++++++++++--------------------------- 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 0f87d0e..c9327a3 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,10 @@ Current workflow categories are: ``` # Download the binary -wget https://github.com/trickest/trickest-cli/releases/download/v1.1.0/trickest-cli-1.1.0-macOS-arm64.zip +wget https://github.com/trickest/trickest-cli/releases/download/v1.1.1/trickest-cli-1.1.1-macOS-arm64.zip # Unzip -unzip trickest-cli-1.1.0-macOS-arm64.zip +unzip trickest-cli-1.1.1-macOS-arm64.zip # Make binary executable chmod +x trickest-cli-macOS-arm64 @@ -55,10 +55,10 @@ trickest --help #### **Linux** ``` -wget https://github.com/trickest/trickest-cli/releases/download/v1.1.0/trickest-cli-1.1.0-linux-amd64.zip +wget https://github.com/trickest/trickest-cli/releases/download/v1.1.1/trickest-cli-1.1.1-linux-amd64.zip # Unzip -unzip trickest-cli-1.1.0-linux-amd64.zip +unzip trickest-cli-1.1.1-linux-amd64.zip # Make binary executable chmod +x trickest-cli-linux-amd64 @@ -148,18 +148,19 @@ Use the **execute** command to execute a particular workflow or tool. trickest execute --workflow --space --config --set-name "New Name" [--watch] ``` -| Flag | Type | Default | Description | -| ------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------- | -| --config | file | / | YAML file for run configuration | -| --workflow | string | / | Workflow from the Store to be executed | -| --max | boolean | / | Use maximum number of machines for workflow execution | -| --output | string | / | A comma-separated list of nodes whose outputs should be downloaded when the execution is finished | -| --output-all | boolean | / | Download all outputs when the execution is finished | -| --output-dir | string | . | Path to the directory which should be used to store outputs | -| --show-params | boolean | / | Show parameters in the workflow tree | -| --watch | boolean | / | Option to track execution status in case workflow is in running state | -| --set-name | string | / | Sets the new workflow name and will copy the workflow to space and project supplied | -| --ci | boolean | false | Enable CI mode (in-progreess executions will be stopped when the CLI is forcefully stopped - if not set, you will be asked for confirmation) | +| Flag | Type | Default | Description | +|------------------|---------|---------|---------------------------------------------------------------------------------------------------------------------------------------------| +| --config | file | / | YAML file for run configuration | +| --workflow | string | / | Workflow from the Store to be executed | +| --max | boolean | / | Use maximum number of machines for workflow execution | +| --output | string | / | A comma-separated list of nodes whose outputs should be downloaded when the execution is finished | +| --output-all | boolean | / | Download all outputs when the execution is finished | +| --output-dir | string | . | Path to the directory which should be used to store outputs | +| --show-params | boolean | / | Show parameters in the workflow tree | +| --watch | boolean | / | Option to track execution status in case workflow is in running state | +| --set-name | string | / | Sets the new workflow name and will copy the workflow to space and project supplied | +| --ci | boolean | false | Enable CI mode (in-progress executions will be stopped when the CLI is forcefully stopped - if not set, you will be asked for confirmation) | +| --create-project | boolean | false | If the project doesn't exist, create one using the project flag as its name (or workflow/tool name if project flag is not set) | #### Provide parameters using **config.yaml** file diff --git a/cmd/execute/execute.go b/cmd/execute/execute.go index 276c05e..9dca1cc 100644 --- a/cmd/execute/execute.go +++ b/cmd/execute/execute.go @@ -37,6 +37,7 @@ var ( outputsDirectory string outputNodesFlag string ci bool + createProject bool ) // ExecuteCmd represents the execute command @@ -111,6 +112,7 @@ func init() { ExecuteCmd.Flags().StringVar(&outputNodesFlag, "output", "", "A comma separated list of nodes which outputs should be downloaded when the execution is finished") ExecuteCmd.Flags().StringVar(&outputsDirectory, "output-dir", "", "Path to directory which should be used to store outputs") ExecuteCmd.Flags().BoolVar(&ci, "ci", false, "Run in CI mode (in-progreess executions will be stopped when the CLI is forcefully stopped - if not set, you will be asked for confirmation)") + ExecuteCmd.Flags().BoolVar(&createProject, "create-project", false, "If the project doesn't exist, create it using the project flag as its name (or workflow name if not set)") } func readWorkflowYAMLandCreateVersion(fileName string, workflowName string, objectPath string) *types.WorkflowVersionDetailed { @@ -912,24 +914,13 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed { // Executing from store for _, wf := range storeWorkflows { if strings.ToLower(wf.Name) == strings.ToLower(wfName) { - if project == nil { + if project == nil && createProject { projectName := util.ProjectName if projectName == "" { projectName = wfName } - fmt.Println("Would you like to create a project named " + projectName + - " and save the new workflow in there? (Y/N)") - var answer string - for { - _, _ = fmt.Scan(&answer) - if strings.ToLower(answer) == "y" || strings.ToLower(answer) == "yes" { - project = create.CreateProjectIfNotExists(space, projectName) - projectCreated = true - break - } else if strings.ToLower(answer) == "n" || strings.ToLower(answer) == "no" { - break - } - } + project = create.CreateProjectIfNotExists(space, projectName) + projectCreated = true } if newWorkflowName == "" { @@ -1014,20 +1005,13 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed { } _, _, primitiveNodes = readConfig(configFile, nil, &tools[0]) - if project == nil { - fmt.Println("Would you like to create a project named " + wfName + - " and save the new workflow in there? (Y/N)") - var answer string - for { - _, _ = fmt.Scan(&answer) - if strings.ToLower(answer) == "y" || strings.ToLower(answer) == "yes" { - project = create.CreateProjectIfNotExists(space, tools[0].Name) - projectCreated = true - break - } else if strings.ToLower(answer) == "n" || strings.ToLower(answer) == "no" { - break - } + if project == nil && createProject { + projectName := util.ProjectName + if projectName == "" { + projectName = wfName } + project = create.CreateProjectIfNotExists(space, tools[0].Name) + projectCreated = true } if newWorkflowName == "" { newWorkflowName = wfName