Skip to content

Commit

Permalink
Merge pull request #54 from trickest/improvement/execute
Browse files Browse the repository at this point in the history
Improvement to `execute` command
  • Loading branch information
Mohammed Diaa authored Jun 15, 2022
2 parents 32024fe + 9bacf6f commit 352406b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ trickest store search subdomain takeover
```

## Report Bugs / Feedback

We look forward to any feedback you want to share with us or if you're stuck with a problem you can contact us at [[email protected]](mailto:[email protected]).

You can also create an [Issue](https://github.com/trickest/trickest-cli/issues/new/choose) in the Github repository.
36 changes: 21 additions & 15 deletions cmd/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var ExecuteCmd = &cobra.Command{
util.SpaceName = "Playground"
}
path := util.FormatPath()
if path == "" || path == "Playground" {
if path == "" {
if len(args) == 0 {
fmt.Println("Workflow name or path must be specified!")
return
Expand All @@ -73,8 +73,10 @@ var ExecuteCmd = &cobra.Command{
}
var version *types.WorkflowVersionDetailed
if workflowYAML != "" {
// Executing from a file
version = readWorkflowYAMLandCreateVersion(workflowYAML, newWorkflowName, path)
} else {
// Executing an existing workflow or copying from store
version = prepareForExec(path)
}
if version == nil {
Expand All @@ -97,7 +99,7 @@ var ExecuteCmd = &cobra.Command{
}

func init() {
ExecuteCmd.Flags().StringVar(&newWorkflowName, "name", "", "New workflow name (used when creating tool workflows or copying store workflows)")
ExecuteCmd.Flags().StringVar(&newWorkflowName, "set-name", "", "Set workflow name")
ExecuteCmd.Flags().StringVar(&configFile, "config", "", "YAML file for run configuration")
ExecuteCmd.Flags().BoolVar(&watch, "watch", false, "Watch the execution running")
ExecuteCmd.Flags().BoolVar(&showParams, "show-params", false, "Show parameters in the workflow tree")
Expand Down Expand Up @@ -799,7 +801,7 @@ func readWorkflowYAMLandCreateVersion(fileName string, workflowName string, obje
projectID = project.ID
}
if workflowName == "" {
fmt.Println("Use --name flag when trying to create a new workflow.")
fmt.Println("Use --set-name flag when trying to create a new workflow.")
os.Exit(0)
}
newWorkflow := create.CreateWorkflow(workflowName, "", space.ID, projectID, true)
Expand Down Expand Up @@ -1230,10 +1232,25 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
if space == nil {
os.Exit(0)
}
if workflow == nil {

if workflow != nil && newWorkflowName == "" {
// Executing an existing workflow
wfVersion = GetLatestWorkflowVersion(workflow)
if configFile == "" {
executionMachines = wfVersion.MaxMachines
} else {
update, updatedWfVersion, newPrimitiveNodes := readConfig(configFile, wfVersion, nil)
if update {
uploadFilesIfNeeded(newPrimitiveNodes)
wfVersion = createNewVersion(updatedWfVersion)
}
}
} else {
// Executing from store
wfName := pathSplit[len(pathSplit)-1]
storeWorkflows := list.GetWorkflows("", "", wfName, true)
if storeWorkflows != nil && len(storeWorkflows) > 0 {
// Executing from store
for _, wf := range storeWorkflows {
if strings.ToLower(wf.Name) == strings.ToLower(wfName) {
storeWfVersion := GetLatestWorkflowVersion(list.GetWorkflowByID(wf.ID))
Expand Down Expand Up @@ -1331,17 +1348,6 @@ func prepareForExec(objectPath string) *types.WorkflowVersionDetailed {
wfVersion = createToolWorkflow(newWorkflowName, space, project, projectCreated, &tools[0], primitiveNodes, executionMachines)

return wfVersion
} else {
wfVersion = GetLatestWorkflowVersion(workflow)
if configFile == "" {
executionMachines = wfVersion.MaxMachines
} else {
update, updatedWfVersion, newPrimitiveNodes := readConfig(configFile, wfVersion, nil)
if update {
uploadFilesIfNeeded(newPrimitiveNodes)
wfVersion = createNewVersion(updatedWfVersion)
}
}
}

return wfVersion
Expand Down

0 comments on commit 352406b

Please sign in to comment.