Home > User Guide > Arguments
Targets can accept typed arguments from the command line.
stringintboolfloat64time.Duration
Add parameters after the optional context:
func Greet(name string, times int) error {
for i := 0; i < times; i++ {
fmt.Printf("Hello, %s!\n", name)
}
return nil
}Pass arguments positionally after the target name:
stave greet Alice 3Output:
Hello, Alice!
Hello, Alice!
Hello, Alice!
Arguments are parsed according to their declared type:
| Type | Example Input | Parsed Value |
|---|---|---|
string |
hello |
"hello" |
int |
42 |
42 |
bool |
true, false, 1, 0 |
true, false |
float64 |
3.14 |
3.14 |
time.Duration |
5m30s |
5*time.Minute + 30*time.Second |
Context and arguments can be combined:
func Deploy(ctx context.Context, env string, dryRun bool) error {
if dryRun {
fmt.Printf("Would deploy to %s\n", env)
return nil
}
// actual deployment
return nil
}stave deploy production falseUse st.F to pass arguments when declaring dependencies:
func Deploy(env string) error {
fmt.Printf("Deploying to %s\n", env)
return nil
}
func DeployAll() {
st.Deps(
st.F(Deploy, "staging"),
st.F(Deploy, "production"),
)
}Each st.F call with distinct arguments is a separate dependency. Both run (in parallel by default), each exactly once.
Missing or malformed arguments cause Stave to exit with code 2:
stave greet Alice
# Error: not enough arguments for target "Greet", expected 2, got 1stave greet Alice notanumber
# Error: can't convert argument "notanumber" to intUse stave -i to see a target's arguments:
stave -i greetOutput:
Usage:
stave greet <name> <times>
- Targets - Defining targets
- Dependencies - Using
st.Fwith arguments - Home