Skip to content

Commit

Permalink
Merge pull request #72 from trickest/create-project-flag
Browse files Browse the repository at this point in the history
Add flag for creating non-existing projects before execution
  • Loading branch information
mhmdiaa authored Aug 17, 2022
2 parents 1d495e1 + d104973 commit 0b3aac5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 43 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -148,18 +148,19 @@ Use the **execute** command to execute a particular workflow or tool.
trickest execute --workflow <workflow_or_tool_name> --space <space_name> --config <config_file_path> --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

Expand Down
38 changes: 11 additions & 27 deletions cmd/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
outputsDirectory string
outputNodesFlag string
ci bool
createProject bool
)

// ExecuteCmd represents the execute command
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0b3aac5

Please sign in to comment.