Skip to content

Commit 76defed

Browse files
Merge pull request #17 from actionforge/cli-flags
Update CLI flag naming to hyphens
2 parents 2d884da + 88391f6 commit 76defed

16 files changed

Lines changed: 55 additions & 42 deletions

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"CGO_ENABLED": "0"
1414
},
1515
"args": [
16-
"--env_file=${workspaceFolder}/.env",
16+
"/Users/sebastian/Desktop/test.act",
17+
"--config_file=/Users/sebastian/Desktop/test.actconfig",
18+
"--concurrency=1"
1719
]
1820
},
1921
{

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ actrun ./my_graph.act --target="production" --verbose
6262
If you need to strictly separate CLI flags from graph arguments, use the `--` separator:
6363

6464
```bash
65-
actrun --env_file=.env -- ./my_graph.act --target="production"
65+
actrun --env-file=.env -- ./my_graph.act --target="production"
6666

6767

6868
```
6969

7070
### 🌍 3. Load Environment Variables
7171

72-
Inject environment variables from a file before execution starts using `--env_file`.
72+
Inject environment variables from a file before execution starts using `--env-file`.
7373

7474
```bash
75-
actrun --env_file=.env.local ./my_graph.act
75+
actrun --env-file=.env.local ./my_graph.act
7676

7777

7878
```
@@ -91,10 +91,10 @@ actrun validate ./complex_workflow.act
9191

9292
### 🕸️ Debug Sessions
9393

94-
`actrun` can bridge your local terminal to the Actionforge web app for visual debugging. You can either connect to your browser session via a debug session token that your browser provided, or you can let the CLI intiate a debug session by using `--create_debug_session`. The latter will print a link to stdout that you can open in your browser and the debug session will immediately begin.
94+
`actrun` can bridge your local terminal to the Actionforge web app for visual debugging. You can either connect to your browser session via a debug session token that your browser provided, or you can let the CLI intiate a debug session by using `--create-debug-session`. The latter will print a link to stdout that you can open in your browser and the debug session will immediately begin.
9595

9696
```bash
97-
actrun --create_debug_session ./my_graph.act
97+
actrun --create-debug-session ./my_graph.act
9898

9999

100100
```

cmd/cmd_root.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"flag"
88
"fmt"
99
"os"
10+
"strings"
1011

1112
"github.com/actionforge/actrun-cli/build"
1213
"github.com/actionforge/actrun-cli/core"
@@ -17,6 +18,7 @@ import (
1718
"github.com/fatih/color"
1819
"github.com/inconshreveable/mousetrap"
1920
"github.com/spf13/cobra"
21+
"github.com/spf13/pflag"
2022

2123
// initialize all nodes
2224
_ "github.com/actionforge/actrun-cli/nodes"
@@ -140,9 +142,9 @@ var cmdRoot = &cobra.Command{
140142
}
141143

142144
if finalCreateDebugSession && finalSessionToken != "" {
143-
return errors.New("both --session_token and --create_debug_session cannot be used together")
145+
return errors.New("both --session-token and --create-debug-session cannot be used together")
144146
} else if finalCreateDebugSession && finalGraphFile == "" {
145-
return errors.New("when using --create_debug_session, a graph file must be specified")
147+
return errors.New("when using --create-debug-session, a graph file must be specified")
146148
}
147149

148150
return nil
@@ -200,6 +202,11 @@ func Execute() {
200202
}
201203
}
202204

205+
// Allow both variations, both --env-file and --env_file will work
206+
func normalizeFlag(f *pflag.FlagSet, name string) pflag.NormalizedName {
207+
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
208+
}
209+
203210
func init() {
204211
flag.Usage = func() {
205212
fmt.Print("\n")
@@ -214,12 +221,16 @@ func init() {
214221
fmt.Print("\n\n")
215222
}
216223

217-
cmdRoot.PersistentFlags().StringVar(&flagEnvFile, "env_file", "", "Absolute path to an env file (.env) to load before execution")
224+
// Enable backwards compatibility: allow both --env-file and --env_file
225+
cmdRoot.PersistentFlags().SetNormalizeFunc(normalizeFlag)
226+
cmdRoot.Flags().SetNormalizeFunc(normalizeFlag)
227+
228+
cmdRoot.PersistentFlags().StringVar(&flagEnvFile, "env-file", "", "Absolute path to an env file (.env) to load before execution")
218229

219-
cmdRoot.Flags().StringVar(&flagConfigFile, "config_file", "", "The config file to use")
230+
cmdRoot.Flags().StringVar(&flagConfigFile, "config-file", "", "The config file to use")
220231
cmdRoot.Flags().StringVar(&flagConcurrency, "concurrency", "", "Enable or disable concurrency")
221-
cmdRoot.Flags().StringVar(&flagSessionToken, "session_token", "", "The session token from your browser")
222-
cmdRoot.Flags().BoolVar(&flagCreateDebugSession, "create_debug_session", false, "Create a debug session by connecting to the web app")
232+
cmdRoot.Flags().StringVar(&flagSessionToken, "session-token", "", "The session token from your browser")
233+
cmdRoot.Flags().BoolVar(&flagCreateDebugSession, "create-debug-session", false, "Create a debug session by connecting to the web app")
223234

224235
// disable interspersed flag parsing to allow passing arbitrary flags to graphs.
225236
// it stops cobra from parsing flags once it hits positional argument

sessions/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func RunSessionMode(configFile string, graphFileForDebugSession string, sessionT
262262
done := make(chan os.Signal, 1)
263263
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
264264

265-
// if browser disconnects during a --create_debug_session run, we switch to detached mode
265+
// if browser disconnects during a --create-debug-session run, we switch to detached mode
266266
// to ensure the graph finishes execution instead of hanging on a breakpoint.
267267
var detachMu sync.Mutex
268268
var detachedMode bool
@@ -503,7 +503,7 @@ func RunSessionMode(configFile string, graphFileForDebugSession string, sessionT
503503
currentDebugOps.cachedState = nil
504504
currentDebugOps.Unlock()
505505

506-
// if this was a one-off debug session (initiated by --create_debug_session), exit the process when graph completes
506+
// if this was a one-off debug session (initiated by --create-debug-session), exit the process when graph completes
507507
if graphFileForDebugSession != "" {
508508
done <- syscall.SIGTERM
509509
}

tests_e2e/references/reference_app.sh_l10

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Available Commands:
1212

1313
Flags:
1414
--concurrency string Enable or disable concurrency
15-
--config_file string The config file to use
16-
--create_debug_session Create a debug session by connecting to the web app
17-
--env_file string Absolute path to an env file (.env) to load before execution
15+
--config-file string The config file to use
16+
--create-debug-session Create a debug session by connecting to the web app
17+
--env-file string Absolute path to an env file (.env) to load before execution
1818
-h, --help help for actrun
19-
--session_token string The session token from your browser
19+
--session-token string The session token from your browser
2020
-v, --version version for actrun
2121

2222
Use "actrun [command] --help" for more information about a command.

tests_e2e/references/reference_app.sh_l12

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ stack trace:
2525
github.com/actionforge/actrun-cli/core.RunGraphFromFile
2626
graph.go:1123
2727
github.com/actionforge/actrun-cli/cmd.cmdRootRun
28-
cmd_root.go:186
28+
cmd_root.go:188
2929
github.com/spf13/cobra.(*Command).execute
3030
command.go:-1
3131
github.com/spf13/cobra.(*Command).ExecuteC
3232
command.go:-1
3333
github.com/spf13/cobra.(*Command).Execute
3434
command.go:-1
3535
github.com/actionforge/actrun-cli/cmd.Execute
36-
cmd_root.go:198
36+
cmd_root.go:200
3737
main.main
3838
main.go:26
3939
runtime.main

tests_e2e/references/reference_contexts_env.sh_l26

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Available Commands:
1212

1313
Flags:
1414
--concurrency string Enable or disable concurrency
15-
--config_file string The config file to use
16-
--create_debug_session Create a debug session by connecting to the web app
17-
--env_file string Absolute path to an env file (.env) to load before execution
15+
--config-file string The config file to use
16+
--create-debug-session Create a debug session by connecting to the web app
17+
--env-file string Absolute path to an env file (.env) to load before execution
1818
-h, --help help for actrun
19-
--session_token string The session token from your browser
19+
--session-token string The session token from your browser
2020
-v, --version version for actrun
2121

2222
Use "actrun [command] --help" for more information about a command.

tests_e2e/references/reference_dir-walk.sh_l56

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ github.com/actionforge/actrun-cli/core.RunGraphFromString
4646
github.com/actionforge/actrun-cli/core.RunGraphFromFile
4747
graph.go:1126
4848
github.com/actionforge/actrun-cli/cmd.cmdRootRun
49-
cmd_root.go:186
49+
cmd_root.go:188
5050
github.com/spf13/cobra.(*Command).execute
5151
command.go:-1
5252
github.com/spf13/cobra.(*Command).ExecuteC
5353
command.go:-1
5454
github.com/spf13/cobra.(*Command).Execute
5555
command.go:-1
5656
github.com/actionforge/actrun-cli/cmd.Execute
57-
cmd_root.go:198
57+
cmd_root.go:200
5858
main.main
5959
main.go:26
6060
runtime.main

tests_e2e/references/reference_error_no_output.sh_l8

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ github.com/actionforge/actrun-cli/core.RunGraphFromString
5757
github.com/actionforge/actrun-cli/core.RunGraphFromFile
5858
graph.go:1126
5959
github.com/actionforge/actrun-cli/cmd.cmdRootRun
60-
cmd_root.go:186
60+
cmd_root.go:188
6161
github.com/spf13/cobra.(*Command).execute
6262
command.go:-1
6363
github.com/spf13/cobra.(*Command).ExecuteC
6464
command.go:-1
6565
github.com/spf13/cobra.(*Command).Execute
6666
command.go:-1
6767
github.com/actionforge/actrun-cli/cmd.Execute
68-
cmd_root.go:198
68+
cmd_root.go:200
6969
main.main
7070
main.go:26
7171
runtime.main

tests_e2e/references/reference_group-port-collision.sh_l13

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ github.com/actionforge/actrun-cli/core.RunGraphFromString
3737
github.com/actionforge/actrun-cli/core.RunGraphFromFile
3838
graph.go:1126
3939
github.com/actionforge/actrun-cli/cmd.cmdRootRun
40-
cmd_root.go:186
40+
cmd_root.go:188
4141
github.com/spf13/cobra.(*Command).execute
4242
command.go:-1
4343
github.com/spf13/cobra.(*Command).ExecuteC
4444
command.go:-1
4545
github.com/spf13/cobra.(*Command).Execute
4646
command.go:-1
4747
github.com/actionforge/actrun-cli/cmd.Execute
48-
cmd_root.go:198
48+
cmd_root.go:200
4949
main.main
5050
main.go:26
5151
runtime.main

0 commit comments

Comments
 (0)