Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read Taskfiles from stdin #1483

Merged
merged 5 commits into from
Feb 22, 2024
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
2 changes: 1 addition & 1 deletion docs/docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ toc_max_heading_level: 5

Task command line tool has the following syntax:

```bash
```shell
task [--flags] [tasks...] [-- CLI_ARGS...]
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tasks:
- ./foo-printer.bash
```

```bash
```shell
#!/bin/bash
a=foo
echo $a
Expand Down
43 changes: 22 additions & 21 deletions docs/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Task offers many installation methods. Check out the available methods below.
If you're on macOS or Linux and have [Homebrew][homebrew] installed, getting
Task is as simple as running:

```bash
```shell
brew install go-task/tap/go-task
```

Expand All @@ -25,24 +25,25 @@ Recently, Task was also made available
[on the official Homebrew repository](https://formulae.brew.sh/formula/go-task),
so you also have that option if you prefer:

```bash
```shell
brew install go-task
```

### Tea

If you're on macOS or Linux and have [tea][tea] installed, getting
Task is as simple as running:
If you're on macOS or Linux and have [tea][tea] installed, getting Task is as
simple as running:

```bash
```shell
tea task
```

or, if you have tea’s magic enabled:

```bash
```shell
task
```

This installation method is community owned. After a new release of Task, they
are automatically released by tea in a minimum of time.

Expand All @@ -51,7 +52,7 @@ are automatically released by tea in a minimum of time.
Task is available in [Snapcraft][snapcraft], but keep in mind that your Linux
distribution should allow classic confinement for Snaps to Task work right:

```bash
```shell
sudo snap install task --classic
```

Expand All @@ -60,7 +61,7 @@ sudo snap install task --classic
If you're on Windows and have [Chocolatey][choco] installed, getting Task is as
simple as running:

```bash
```shell
choco install go-task
```

Expand All @@ -71,7 +72,7 @@ This installation method is community owned.
If you're on Windows and have [Scoop][scoop] installed, getting Task is as
simple as running:

```cmd
```shell
scoop install task
```

Expand All @@ -84,7 +85,7 @@ If you're on Arch Linux you can install Task from
[AUR](https://aur.archlinux.org/packages/go-task-bin) using your favorite
package manager such as `yay`, `pacaur` or `yaourt`:

```cmd
```shell
yay -S go-task-bin
```

Expand All @@ -93,7 +94,7 @@ Alternatively, there's
the source code instead of downloading the binary from the
[releases page](https://github.com/go-task/task/releases):

```cmd
```shell
yay -S go-task
```

Expand All @@ -105,7 +106,7 @@ If you're on Fedora Linux you can install Task from the official
[Fedora](https://packages.fedoraproject.org/pkgs/golang-github-task/go-task/)
repository using `dnf`:

```cmd
```shell
sudo dnf install go-task
```

Expand All @@ -118,7 +119,7 @@ take some time until it's available in
If you're on NixOS or have Nix installed you can install Task from
[nixpkgs](https://github.com/NixOS/nixpkgs):

```cmd
```shell
nix-env -iA nixpkgs.go-task
```

Expand All @@ -131,7 +132,7 @@ take some time until it's available in
You can also use Node and npm to install Task by installing
[this package](https://www.npmjs.com/package/@go-task/cli).

```bash
```shell
npm install -g @go-task/cli
```

Expand All @@ -141,7 +142,7 @@ If you are using Windows and installed the
[winget](https://github.com/microsoft/winget-cli) package management tool, you
can install Task from [winget-pkgs](https://github.com/microsoft/winget-pkgs).

```bash
```shell
winget install Task.Task
```

Expand All @@ -165,15 +166,15 @@ easy generation of this script.
By default, it installs on the `./bin` directory relative to the working
directory:

```bash
```shell
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
```

It is possible to override the installation directory with the `-b` parameter.
On Linux, common choices are `~/.local/bin` and `~/bin` to install for the
current user or `/usr/local/bin` to install for all users:

```bash
```shell
sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
```

Expand Down Expand Up @@ -209,13 +210,13 @@ setup. You can find the minimum required version of Go in the

You can then install the latest release globally by running:

```bash
```shell
go install github.com/go-task/task/v3/cmd/task@latest
```

Or you can install into another directory:

```bash
```shell
env GOBIN=/bin go install github.com/go-task/task/v3/cmd/task@latest
```

Expand All @@ -239,7 +240,7 @@ First, ensure that you installed bash-completion using your package manager.

Make the completion file executable:

```
```shell
chmod +x path/to/task.bash
```

Expand Down Expand Up @@ -278,7 +279,7 @@ mv path/to/task.fish ~/.config/fish/completions/task.fish

Open your profile script with:

```
```powershell
mkdir -Path (Split-Path -Parent $profile) -ErrorAction SilentlyContinue
notepad $profile
```
Expand Down
42 changes: 27 additions & 15 deletions docs/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tasks:

Running the tasks is as simple as running:

```bash
```shell
task assets build
```

Expand Down Expand Up @@ -118,6 +118,18 @@ tasks:

:::

### Reading a Taskfile from stdin

Taskfile also supports reading from stdin. This is useful if you are generating
Taskfiles dynamically and don't want write them to disk. This works just like
any other program that supports stdin. For example:

```shell
task < <(cat ./Taskfile.yml)
# OR
cat ./Taskfile.yml | task
```

## Environment variables

### Task
Expand Down Expand Up @@ -162,11 +174,11 @@ variables, as you can see in the [Variables](#variables) section.
You can also ask Task to include `.env` like files by using the `dotenv:`
setting:

```bash title=".env"
```shell title=".env"
KEYNAME=VALUE
```

```bash title="testing/.env"
```shell title="testing/.env"
ENDPOINT=testing.com
```

Expand Down Expand Up @@ -699,7 +711,7 @@ path like `tmp/task` that will be interpreted as relative to the project
directory, or an absolute or home path like `/tmp/.task` or `~/.task`
(subdirectories will be created for each project).

```bash
```shell
export TASK_TEMP_DIR='~/.task'
```

Expand Down Expand Up @@ -950,7 +962,7 @@ listed below in order of importance (i.e. most important first):

Example of sending parameters with environment variables:

```bash
```shell
$ TASK_VARIABLE=a-value task do-something
```

Expand All @@ -964,7 +976,7 @@ Since some shells do not support the above syntax to set environment variables
(Windows) tasks also accept a similar style when not at the beginning of the
command.

```bash
```shell
$ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!"
```

Expand Down Expand Up @@ -1192,7 +1204,7 @@ If `--` is given in the CLI, all following parameters are added to a special

The below example will run `yarn install`.

```bash
```shell
$ task yarn -- install
```

Expand Down Expand Up @@ -1353,7 +1365,7 @@ tasks:

would print the following output:

```bash
```shell
* build: Build the go binary.
* test: Run all the go tests.
```
Expand Down Expand Up @@ -1486,7 +1498,7 @@ tasks:
- echo 'dangerous command'
```

```bash
```shell
❯ task dangerous
task: "This is a dangerous command... Do you want to continue?" [y/N]
```
Expand All @@ -1495,7 +1507,7 @@ Warning prompts are called before executing a task. If a prompt is denied Task
will exit with [exit code](/api#exit-codes) 205. If approved, Task will continue
as normal.

```bash
```shell
❯ task example
not dangerous command
task: "This is a dangerous command. Do you want to continue?" [y/N]
Expand Down Expand Up @@ -1532,14 +1544,14 @@ tasks:

Normally this will be printed:

```sh
```shell
echo "Print something"
Print something
```

With silent mode on, the below will be printed instead:

```sh
```shell
Print something
```

Expand Down Expand Up @@ -1686,7 +1698,7 @@ tasks:
silent: true
```

```bash
```shell
$ task default
::group::default
Hello, World!
Expand All @@ -1711,7 +1723,7 @@ tasks:
errors: echo 'output-of-errors' && exit 1
```

```bash
```shell
$ task passes
$ task errors
output-of-errors
Expand Down Expand Up @@ -1744,7 +1756,7 @@ tasks:
silent: true
```

```bash
```shell
$ task default
[print-foo] foo
[print-bar] bar
Expand Down
7 changes: 6 additions & 1 deletion docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ const config: Config = {
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme
darkTheme: darkCodeTheme,
additionalLanguages: [
"bash", // aka. shell
"json",
"powershell"
]
},
// NOTE(@andreynering): Don't worry, these keys are meant to be public =)
algolia: {
Expand Down
17 changes: 7 additions & 10 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,19 @@ func (e *Executor) setCurrentDir() error {
return err
}
e.Dir = wd
} else {
var err error
e.Dir, err = filepath.Abs(e.Dir)
if err != nil {
return err
}
}

// Search for a taskfile
root, err := taskfile.ExistsWalk(e.Dir)
if err != nil {
return err
}
e.Dir = filepath.Dir(root)
e.Entrypoint = filepath.Base(root)

return nil
}

func (e *Executor) readTaskfile() error {
uri := filepath.Join(e.Dir, e.Entrypoint)
node, err := taskfile.NewNode(uri, e.Insecure)
node, err := taskfile.NewRootNode(e.Dir, e.Entrypoint, e.Insecure)
if err != nil {
return err
}
Expand Down
Loading
Loading