Giter VIP home page Giter VIP logo

megabyte-labs / bodega Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 9.6 MB

๐Ÿ˜‰ A gorgeous, feature-packed drop-in replacement for the go-task project ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

Home Page: https://megabyte.space

License: Other

Ruby 4.51% JavaScript 0.83% Shell 31.04% Dockerfile 0.07% Go 63.37% PowerShell 0.18%
automation cli go go-lang golang mblabs megabytelabs professormanhattan terminal washingtondc

bodega's Introduction

Bodega - Your Go-To Task Runner



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


Table of Contents

Overview

Bodega is an improved version of go-task that brings a slew of new features and improvements. It 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

---
version: '3'

tasks:
  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'

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

---
version: '3'

tasks:
  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

---
version: '3'

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

---
version: '3'

tasks:
  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

Output custom messages on task success/failure

Customize the output message if the task successfully ran or failed. You can also define a custom message that runs before the task start.

---
version: '3'

tasks:
  custom-logs:
    run: once
    desc: 'includes custom messages on start/stop and error'
    cmds:
      - echo 'hey'
      - cmd: exit 99
        ignore_error: true
      - cmd: exit 12
        ignore_error: false
    log:
      success: 'hello custom-logs task'
      start: 'Log message to show before Go starts running the task logic (including env scripts)'
      error:
        default: 'Log message to show if the cmds return exit code 1 or greater'
        codes: # optional!
          - code: 12
            message: 'code exited with error code 12'

If the task exited with a particular error number, you may also tailor a speicific message for each error code with the codes field. Running the above task should output:

hello custom-logs task
task: [custom-logs] echo 'hey'
hey
task: [custom-logs] exit 99
task: [custom-logs] exit 12
code exited with error code 12
task: Failed to run task "custom-logs": exit status 12

[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/megabyte-labs/Bodega.git
cd {{#withLast (split repository.github "/")}}this/withLast
go build -o dist/task cmd/task/task.go
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 [-ilfwvsdm] [--init] [--list] [--force] [--watch] [--verbose] [--silent] [--dir] [--taskfile] [--dry] [--menu] [--summary] [--debug] [task...]

Runs the specified task(s). Runs a built-in shell 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
      --debug             stop before each command execution
  -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
  -m, --menu              runs an interactive listing of tasks
  -o, --output string     sets output style: [interleaved|group|prefixed]
  -p, --parallel          executes tasks provided on command line in parallel
      --server            runs as a server
  -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"
      --use-tls           enable server to use TLS
  -v, --verbose count     enables verbose mode (repeat option for more output)
      --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.

Sponsorship

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.

bodega's People

Contributors

amancevice avatar andreynering avatar bebbs avatar caarlos0 avatar chris-garrett avatar danquah avatar dependabot[bot] avatar evg4b avatar ezhukov avatar frederikhors avatar guillaumeamat avatar jaedle avatar jamieedge avatar kerma avatar marco-m avatar masaushi avatar mccolljr avatar paulvarache avatar professormanhattan avatar rfc2119 avatar rosshammer avatar saromanov avatar sascha-andres avatar semantic-release-bot avatar sheldonhull avatar smyrman avatar stephenprater avatar sylv-io avatar topecongiro avatar zbindenren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.