Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

go-bodega

A gorgeous, feature-packed drop-in replacement for the go-task project

automation, cli, go, go-lang, golang, mblabs, megabytelabs, professormanhattan, terminal, washingtondc

readme

Bodega - An Invaluable Task Runner Known

Megabyte Labs



subheader_description


terminalizer_title

Table of Contents

* [Overview](#overview)
* [Features](#features)
    * [Prompt](#prompt)
    * [Initial Shell Script](#initial-shell-script)

Overview

Bodega is a fork of go-task that adds powerful UX features and functional improvements while retaining backwards compatibility. For those of you who do not know, Task is a task runner / Make alternative written in Go. It allows you to define bash script snippets in YML files and provides some advanced features. Some of the features it includes is the ability to define dependencies, running tasks conditionally, caching values, and a built-in method of housing CLI documentation. Bodega takes go-task to the next level by improving the TUI experience and including features that allow you to use the project as a CLI-generator.

Features

Prompt

A prompt field provides an interactive method of getting user data. In addition, it controls execution with the validate sub-field which, on correct input, executes the task answer. The user's selection (or input) is available as the .ANSWER template variable

test_prompt:
  vars:
    TEST: 'string'
  prompt:
    # available types:
    # multiline, multi_select, select, password, confirm, input
    type: input
    message: What day is it?
    # The options sub-field is used with propmpts of type select and multi_select
    # options:
    #   - msg: Sunday
    #   - Tuesday
    # The following is a dynamic option
    #   - msg:
    #       sh: date +%A
    validate:
      sh: '[[ ".ANSWER" == "Tuesday" ]]'
    answer:
      desc: 'a task executed on valid input only'
      cmds:
        - echo "successfully executing the answer task"

Initial Shell Script

The field shell_rc is used to load common shell scripts or functions. It can be specified both globally (on the Taskfile level) and locally (on each individual task). Commands inside each task loads the shell_rc field before exeution.

version: '3'


<a href="#a-global-shell_rc" style="width:100%"><img style="width:100%" src="https://gitlab.com/megabyte-labs/assets/-/raw/master/png/aqua-divider.png" /></a>

# }A global shell_rc
shell_rc: |
    func(){
      echo "global function called!"
    }

tasks:

  init-script-global:
    desc: Testing a local shell_rc field
    cmds:
    - echo "trying out the global shell_rc field"
    - func

  init-script:
    desc: Testing a local shell_rc field
    shell_rc: |
      export VAR_INSIDE_INIT_SCRIPT="Hello from init script"
      func(){
        echo "local function called!"
      }
    cmds:
      - echo "This is a var inside init_script $VAR_INSIDE_INIT_SCRIPT"
      - func
      - sleep 2   # doing some work

Hide tasks from being listed

The hide field allows a task to not be listed with task --list It can be also templated using Go templates

remember that Go is strongly typed. comparison must be done between equal types use double quotes for literals inside templates

error-with-hide:
  desc: A hidden task that exits with an errors
  vars:
    CGO_ENABLED: 'true'
  hide: '{{if eq .CGO_ENABLED "true"}} true else false end'
  # hide: true
  cmds:
    - echo "text"
    - exit 1
    - echo "unreachable"

Initial Status

The initial_status boolean field allows a task to be executed once if the status has been successfully executed once. An initial_status without a status is simple ignored

tasks:
  default:
    cmds:
      - generate-files
      - rm -rf directory/
      - generate-files

  generate-files:
    desc: Generate files diescription
    cmds:
      - mkdir directory
      - touch directory/file1.txt
      - touch directory/file2.txt
    # test existence of files
    status:
      - test -d directory
      - test -f directory/file1.txt
      - test -f directory/file2.txt
    initial_status: true

On running task default from the command line, only the first execution of task generate-files is done

Stop commands before execution

Passing the --debug makes Task stop before each command execution, even for commands within a variable.

$ ./task --debug simple
task: [simple] echo 'hi'
Executing a shell command. Type enter to continue

hi

Aliases

From the command line, you may call a task by its alias instead of its name

echo-with-errors-ignored:
  desc: Echoes a string but with errors ignored
  # Try calling the task from the command line as `task hello`
  alias: hello
  cmds:
    - cmd: exit 1
      ignore_error: true
    - echo "Hello World"

On the command line type task hello to execute the task

More output messages

Running task with more -vs produces more verbose output

Option Effect
-v Output each command executed, task running time
-vv Output execution time of each command

Interactive Prompt

Executing task spawns a REPL-like shell by default. If you would like to execute the default task, please do task default

user@user:$ task
Type 'help' for a list of commands or 'quit' to exit
task> --list

   Tasks

              TASK           │ ALIAS │          DESCRIPTION
  ───────────────────────────┼───────┼─────────────────────────────────
    echo-with-errors-ignored │ hello │ Echoes a string but with
                             │       │ errors ignored
    generate-files           │       │ Generate files diescription
    init-script              │       │ Testing the new shell_rc field
    simple                   │       │ A simple task with no extra
                             │       │ features
    sleep                    │       │ zzzzzzz
    test_prompt              │       │ tests prompt
    test_prompt_confirm      │       │ test prompt confirm
    test_prompt_password     │       │ test prompt password

task> simple
task: [simple] echo "Hello"
Hello
task> sleep
task: [sleep] sleep "2"
task> ^D
readline error: EOF
user@user:$

Fancy listing

task --list uses the list component from bubbletea

bubbletea_list_demo

[WIP] Progress bar

Trach the issue here

Installation

There are several ways you can install this CLI. You can:

  1. Use our bash scripts which will handle everything automatically with as few dependencies as possible
  2. Compile the program using Go and add it to your PATH
  3. Install it via an NPM convienience wrapper
  4. Download the pre-built binary from the GitLab or GitHub releases page and then place it in your PATH

Quick Method

If you are looking to install the CLI as quickly as possible then you can run the following script which will install the binary to your /usr/local/bin folder on macOS or Linux:

curl -sS https://install.doctor/task | bash

Or, if you are on Windows, you can install it by running:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://install.doctor/task?os=win'))

Compile Program with Go

You can install the CLI by compiling it from the source as long as you have a recent version of Go installed:

git clone https://github.com/ProfessorManhattan/Bodega.git
cd {{#withLast (split repository.github "/")}}this}}{{/withLast
.build_command
sudo mv ./dist/task /usr/local/bin

After you compile the program, you should then move the binary file to a location that is in your PATH (which is what the last line does in the snippet above).

NPM Install Method

Every release is bundled into an NPM package that you can install by running the following command:

npm install -g task

Pre-Built Binary

If you trust us (and you should not.. trust.. anybody.. EVER), then you can also download the binary directly from the Bodega GitLab release page or the GitHub release page. After you download the release, you will have to either place the binary somewhere in your PATH or run the installer (in the case of the .deb or .rpm releases, for instance).

Usage

All of the usage instructions can be found by running task --help. After running the command, you should be greeted with the following output:

Usage: task [-ilfwvsd] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--summary] [task...]

Runs the specified task(s). Falls back to the "default" task if no task name
was specified, or lists all tasks if an unknown task name was specified.

Example: 'task hello' with the following 'Taskfile.yml' file will generate an
'output.txt' file with the content "hello".

'''
version: '3'
tasks:
  hello:
    cmds:
      - echo "I am going to write a file named 'output.txt' now."
      - echo "hello" > output.txt
    generates:
      - output.txt
'''

Options:
  -c, --color             colored output. Enabled by default. Set flag to false or use NO_COLOR=1 to disable (default true)
  -C, --concurrency int   limit number tasks to run concurrently
  -d, --dir string        sets directory of execution
      --dry               compiles and prints tasks in the order that they would be run, without executing them
  -f, --force             forces execution even when the task is up-to-date
  -h, --help              shows Task usage
  -i, --init              creates a new Taskfile.yaml in the current folder
  -l, --list              lists tasks with description of current Taskfile
  -a, --list-all          lists tasks with or without a description
  -o, --output string     sets output style: [interleaved|group|prefixed]
  -p, --parallel          executes tasks provided on command line in parallel
  -s, --silent            disables echoing
      --status            exits with non-zero exit code if any of the given tasks is not up-to-date
      --summary           show summary about a task
  -t, --taskfile string   choose which Taskfile to run. Defaults to "Taskfile.yml"
  -v, --verbose           enables verbose mode
      --version           show Task version
  -w, --watch             enables watch of the given task

Man Page

Alternatively, if you installed the package via NPM or an installer that set up the man page (e.g. .deb or .rpm), then you can find usage instructions by running man task.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you would like to contribute, please take a look at the contributing guide.

<summary>Sponsorship</summary>

Dear Awesome Person,

I create open source projects out of love. Although I have a job, shelter, and as much fast food as I can handle, it would still be pretty cool to be appreciated by the community for something I have spent a lot of time and money on. Please consider sponsoring me! Who knows? Maybe I will be able to quit my job and publish open source full time.

Sincerely,

Brian Zalewski

Open Collective sponsors GitHub sponsors Patreon

License

Copyright © 2020-2021 Megabyte LLC. This project is MIT licensed.

changelog

Changelog

v3.10.0 - 2022-01-04

  • A new --list-all (alias -a) flag is now available. It's similar to the exiting --list (-l) but prints all tasks, even those without a description (#383, #401).
  • It's now possible to schedule cleanup commands to run once a task finishes with the defer: keyword (Documentation, #475, #626).
  • Remove long deprecated and undocumented $ variable prefix and ^ command prefix (#642, #644, #645).
  • Add support for .yaml extension (as an alternative to .yml). This was requested multiple times throughout the years. Enjoy! (#183, #184, #369, #584, #621).
  • Fixed error when computing a variable when the task directory do not exist yet (#481, #579).

v3.9.2 - 2021-12-02

v3.9.1 - 2021-11-28

  • Add logging in verbose mode for when a task starts and finishes (#533, #588).
  • Fix an issue with preconditions and context errors (#597, #598).
  • Quote each {{.CLI_ARGS}} argument to prevent one with spaces to become many (#613).
  • Fix nil pointer when cmd: was left empty (#612, #614).
  • Upgrade mvdan/sh which contains two relevant fixes:
    • Fix quote of empty strings in shellQuote (#609, mvdan/sh#763).
    • Fix issue of wrong environment variable being picked when there's another very similar one (#586, mvdan/sh#745).
  • Install shell completions automatically when installing via Homebrew (#264, #592, go-task/homebrew-tap#2).

v3.9.0 - 2021-10-02

v3.8.0 - 2021-09-26

  • Add interactive: true setting to improve support for interactive CLI apps (#217, #563).
  • Fix some nil errors (#534, #573).
  • Add ability to declare an included Taskfile as optional (#519, #552).
  • Add support for including Taskfiles in the home directory by using ~ (#539, #557).

v3.7.3 - 2021-09-04

v3.7.0 - 2021-07-31

  • Add run: setting to control if tasks should run multiple times or not. Available options are always (the default), when_changed (if a variable modified the task) and once (run only once no matter what). This is a long time requested feature. Enjoy! (#53, #359).

v3.6.0 - 2021-07-10

  • Allow using both sources: and status: in the same task (#411, #427, #477).
  • Small optimization and bug fix: don't compute variables if not needed for dotenv: (#517).

v3.5.0 - 2021-07-04

  • Add support for interpolation in dotenv: (#433, #434, #453).

v3.4.3 - 2021-05-30

  • Add support for the NO_COLOR environment variable. (#459, fatih/color#137).
  • Fix bug where sources were not considering the right directory in --watch mode (#484, #485).

v3.4.2 - 2021-04-23

  • On watch, report which file failed to read (#472).
  • Do not try to catch SIGKILL signal, which are not actually possible (#476).
  • Improve version reporting when building Task from source using Go Modules (#462, #473).

v3.4.1 - 2021-04-17

  • Improve error reporting when parsing YAML: in some situations where you would just see an generic error, you'll now see the actual error with more detail: the YAML line the failed to parse, for example (#467).
  • A JSON Schema was published here and is automatically being used by some editors like Visual Studio Code (#135).
  • Print task name before the command in the log output (#398).

v3.3.0 - 2021-03-20

  • Add support for delegating CLI arguments to commands with -- and a special CLI_ARGS variable (#327).
  • Add a --concurrency (alias -C) flag, to limit the number of tasks that run concurrently. This is useful for heavy workloads. (#345).

v3.2.2 - 2021-01-12

  • Improve performance of --list and --summary by skipping running shell variables for these flags (#332).
  • Fixed a bug where an environment in a Taskfile was not always overridable by the system environment (#425).
  • Fixed environment from .env files not being available as variables (#379).
  • The install script is now working for ARM platforms (#428).

v3.2.1 - 2021-01-09

  • Fixed some bugs and regressions regarding dynamic variables and directories (#426).
  • The slim-sprig package was updated with the upstream sprig.

v3.2.0 - 2021-01-07

  • Fix the .task directory being created in the task directory instead of the Taskfile directory (#247).
  • Fix a bug where dynamic variables (those declared with sh:) were not running in the task directory when the task has a custom dir or it was in an included Taskfile (#384).
  • The watch feature (via the --watch flag) got a few different bug fixes and should be more stable now (#423, #365).

v3.1.0 - 2021-01-03

  • Fix a bug when the checksum up-to-date resolution is used by a task with a custom label: attribute (#412).
  • Starting from this release, we're releasing official ARMv6 and ARM64 binaries for Linux (#375, #418).
  • Task now respects the order of declaration of included Taskfiles when evaluating variables declaring by them (#393).
  • set -e is now automatically set on every command. This was done to fix an issue where multiline string commands wouldn't really fail unless the sentence was in the last line (#403).

v3.0.1 - 2020-12-26

  • Allow use as a library by moving the required packages out of the internal directory (#358).
  • Do not error if a specified dotenv file does not exist (#378, #385).
  • Fix panic when you have empty tasks in your Taskfile (#338, #362).

v3.0.0 - 2020-08-16

  • On v3, all CLI variables will be considered global variables (#336, #341)
  • Add support to .env like files (#324, #356).
  • Add label: to task so you can override the task name in the logs (#321, #337).
  • Refactor how variables work on version 3 (#311).
  • Disallow expansions on v3 since it has no effect.
  • Taskvars.yml is not automatically included anymore.
  • Taskfile_{{OS}}.yml is not automatically included anymore.
  • Allow interpolation on includes, so you can manually include a Taskfile based on operation system, for example.
  • Expose .TASK variable in templates with the task name (#252).
  • Implement short task syntax (#194, #240).
  • Added option to make included Taskfile run commands on its own directory (#260, #144)
  • Taskfiles in version 1 are not supported anymore (#237).
  • Added global method: option. With this option, you can set a default method to all tasks in a Taskfile (#246).
  • Changed default method from timestamp to checksum (#246).
  • New magic variables are now available when using status:: .TIMESTAMP which contains the greatest modification date from the files listed in sources:, and .CHECKSUM, which contains a checksum of all files listed in status:. This is useful for manual checking when using external, or even remote, artifacts when using status: (#216).
  • We're now using slim-sprig instead of sprig, which allowed a file size reduction of about 22% (#219).
  • We now use some colors on Task output to better distinguish message types - commands are green, errors are red, etc (#207).

v2.8.1 - 2020-05-20

  • Fix error code for the --help flag (#300, #330).
  • Print version to stdout instead of stderr (#299, #329).
  • Supress context errors when using the --watch flag (#313, #317).
  • Support templating on description (#276, #283).

v2.8.0 - 2019-12-07

  • Add --parallel flag (alias -p) to run tasks given by the command line in parallel (#266).
  • Fixed bug where calling the task CLI only informing global vars would not execute the default task.
  • Add hability to silent all tasks by adding silent: true a the root of the Taskfile.

v2.7.1 - 2019-11-10

  • Fix error being raised when exit 0 was called (#251).

v2.7.0 - 2019-09-22

  • Fixed panic bug when assigning a global variable (#229, #243).
  • A task with method: checksum will now re-run if generated files are deleted (#228, #238).

v2.6.0 - 2019-07-21

  • Fixed some bugs regarding minor version checks on version:.
  • Add preconditions: to task (#205).
  • Create directory informed on dir: if it doesn't exist (#209, #211).
  • We now have a --taskfile flag (alias -t), which can be used to run another Taskfile (other than the default Taskfile.yml) (#221).
  • It's now possible to install Task using Homebrew on Linux (go-task/homebrew-tap#1).

v2.5.2 - 2019-05-11

  • Reverted YAML upgrade due issues with CRLF on Windows (#201, go-yaml/yaml#450).
  • Allow setting global variables through the CLI (#192).

2.5.1 - 2019-04-27

  • Fixed some issues with interactive command line tools, where sometimes the output were not being shown, and similar issues (#114, #190, #200).
  • Upgraded go-yaml/yaml from v2 to v3.

v2.5.0 - 2019-03-16

v2.4.0 - 2019-02-21

  • Allow calling a task of the root Taskfile from an included Taskfile by prefixing it with : (#161, #172),
  • Add flag to override the output option (#173);
  • Fix bug where Task was persisting the new checksum on the disk when the Dry Mode is enabled (#166);
  • Fix file timestamp issue when the file name has spaces (#176);
  • Mitigating path expanding issues on Windows (#170).

v2.3.0 - 2019-01-02

  • On Windows, Task can now be installed using Scoop (#152);
  • Fixed issue with file/directory globing (#153);
  • Added ability to globally set environment variables ( #138, #159 ).

v2.2.1 - 2018-12-09

  • This repository now uses Go Modules (#143). We'll still keep the vendor directory in sync for some time, though;
  • Fixing a bug when the Taskfile has no tasks but includes another Taskfile (#150);
  • Fix a bug when calling another task or a dependency in an included Taskfile (#151).

v2.2.0 - 2018-10-25

  • Added support for including other Taskfiles (#98)
    • This should be considered experimental. For now, only including local files is supported, but support for including remote Taskfiles is being discussed. If you have any feedback, please comment on #98.
  • Task now have a dedicated documentation site: https://taskfile.org
    • Thanks to Docsify for making this pretty easy. To check the source code, just take a look at the docs directory of this repository. Contributions to the documentation is really appreciated.

v2.1.1 - 2018-09-17

  • Fix suggestion to use task --init not being shown anymore (when a Taskfile.yml is not found)
  • Fix error when using checksum method and no file exists for a source glob (#131)
  • Fix signal handling when the --watch flag is given (#132)

v2.1.0 - 2018-08-19

  • Add a ignore_error option to task and command (#123)
  • Add a dry run mode (--dry flag) (#126)

v2.0.3 - 2018-06-24

  • Expand environment variables on "dir", "sources" and "generates" (#116)
  • Fix YAML merging syntax (#112)
  • Add ZSH completion (#111)
  • Implement new output option. Please check out the documentation

v2.0.2 - 2018-05-01

  • Fix merging of YAML anchors (#112)

v2.0.1 - 2018-03-11

  • Fixes panic on task --list

v2.0.0 - 2018-03-08

Version 2.0.0 is here, with a new Taskfile format.

Please, make sure to read the Taskfile versions document, since it describes in depth what changed for this version.

v1.4.4 - 2017-11-19

  • Handle SIGINT and SIGTERM (#75);
  • List: print message with there's no task with description;
  • Expand home dir ("~" symbol) on paths (#74);
  • Add Snap as an installation method;
  • Move examples to its own repo;
  • Watch: also walk on tasks called on on "cmds", and not only on "deps";
  • Print logs to stderr instead of stdout (#68);
  • Remove deprecated set keyword;
  • Add checksum based status check, alternative to timestamp based.

v1.4.3 - 2017-09-07

  • Allow assigning variables to tasks at run time via CLI (#33)
  • Added suport for multiline variables from sh (#64)
  • Fixes env: remove square braces and evaluate shell (#62)
  • Watch: change watch library and few fixes and improvements
  • When use watching, cancel and restart long running process on file change (#59 and #60)

v1.4.2 - 2017-07-30

  • Flag to set directory of execution
  • Always echo command if is verbose mode
  • Add silent mode to disable echoing of commands
  • Fixes and improvements of variables (#56)

v1.4.1 - 2017-07-15

  • Allow use of YAML for dynamic variables instead of $ prefix
    • VAR: {sh: echo Hello} instead of VAR: $echo Hello
  • Add --list (or -l) flag to print existing tasks
  • OS specific Taskvars file (e.g. Taskvars_windows.yml, Taskvars_linux.yml, etc)
  • Consider task up-to-date on equal timestamps (#49)
  • Allow absolute path in generates section (#48)
  • Bugfix: allow templating when calling deps (#42)
  • Fix panic for invalid task in cyclic dep detection
  • Better error output for dynamic variables in Taskvars.yml (#41)
  • Allow template evaluation in parameters

v1.4.0 - 2017-07-06

  • Cache dynamic variables
  • Add verbose mode (-v flag)
  • Support to task parameters (overriding vars) (#31) (#32)
  • Print command, also when "set:" is specified (#35)
  • Improve task command help text (#35)

v1.3.1 - 2017-06-14

  • Fix glob not working on commands (#28)
  • Add ExeExt template function
  • Add --init flag to create a new Taskfile
  • Add status option to prevent task from running (#27)
  • Allow interpolation on generates and sources attributes (#26)

v1.3.0 - 2017-04-24

  • Migrate from os/exec.Cmd to a native Go sh/bash interpreter
    • This is a potentially breaking change if you use Windows.
    • Now, cmd is not used anymore on Windows. Always use Bash-like syntax for your commands, even on Windows.
  • Add "ToSlash" and "FromSlash" to template functions
  • Use functions defined on github.com/Masterminds/sprig
  • Do not redirect stdin while running variables commands
  • Using context and errgroup packages (this will make other tasks to be cancelled, if one returned an error)

v1.2.0 - 2017-04-02

  • More tests and Travis integration
  • Watch a task (experimental)
  • Possibility to call another task
  • Fix "=" not being reconized in variables/environment variables
  • Tasks can now have a description, and help will print them (#10)
  • Task dependencies now run concurrently
  • Support for a default task (#16)

v1.1.0 - 2017-03-08

  • Support for YAML, TOML and JSON (#1)
  • Support running command in another directory (#4)
  • --force or -f flag to force execution of task even when it's up-to-date
  • Detection of cyclic dependencies (#5)
  • Support for variables (#6, #9, #14)
  • Operation System specific commands and variables (#13)

v1.0.0 - 2017-02-28

  • Add LICENSE file