Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/content/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cd data
list *.tsv
```

The `command` is transpiled into a Go function that takes `args ...string`. In the command function body, you can use the `args...` expression to pass all of the args, or `args[1]` etc to refer to specific positional indexes, as usual.
The `command` is transpiled into a Go function that takes `args ...string` arguments. In the command function body, you can use the `args...` expression to pass all of the args, or `args[1]` etc to refer to specific positional indexes, as usual.

The command function name is registered so that the standard shell execution code can run the function, passing the args. You can also call it directly from Go code using the standard parentheses expression.

Expand All @@ -53,16 +53,16 @@ As with most scripting languages, a file of goal code can be made directly execu
#!/usr/bin/env goal
```

When executed this way, any additional args are available via an `args []any` variable, which can be passed to a command as follows:
When executed this way, any additional args passed on the command line invocation are available via the `goalrun.Args()` function, which can be passed to a command as follows:
```go
install {args...}
install {goalrun.Args()}
```
or by referring to specific arg indexes etc.
or by referring to specific arg indexes etc, as in `goalrun.Args()[0]`. Note that these are not the same as the implicit `args` for command aliases, which are local function args in effect.

To make a script behave like a standard Makefile, you can define different `command`s for each of the make commands, and then add the following at the end of the file to use the args to run commands:

```go
goal.RunCommands(args)
goal.RunCommands(goalrun.Args())
```

See [make](cmd/goal/testdata/make) for an example, in `cmd/goal/testdata/make`, which can be run for example using:
Expand Down
3 changes: 1 addition & 2 deletions goal/cmd/goal/testdata/test.goal
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// test file for goal cli

// todo: doesn't work: #1152
// echo {args}
echo {goalrun.Args()}

for i, fn := range goalib.SplitLines(`/bin/ls -1`) {
fmt.Println(i, fn)
Expand Down