tinka alpha

Command line

This guide covers Tinka's command line. You will learn how to:

Overview

A Command is an action you run from the terminal, such as generating the App's key or publishing the posts scheduled for today. Tinka gives every App a few Commands, and your App adds its own. You run them with act from the App's directory.

Every Command has two audiences. People get text, colors where the terminal shows them, and prompts for what's missing. Agents get Agent mode: no prompts and a single JSON result. You write each Command once, and both work.

Run Commands

Run act with the Command's name, then its arguments and flags:

Terminal
act posts:publish --limit 5

Inside an App, act builds the App and runs its binary with your arguments, so your App's own Commands run with the App's own version of Tinka. The build is cached: act rebuilds only when a source file changed, so a run usually starts in a few milliseconds.

Building and running the App runs its code, so the first time you run one of its Commands, act asks whether you trust the App's directory. Answer y once per App. In CI, or for an agent, run act trust in the App's directory first. See act trust.

The App's main function hands the arguments to the App with Main:

main.go
package main

import (
	"os"

	"github.com/mucolabs/tinka"
)

func main() {
	app := tinka.New(tinka.HTTPConfig{})
	// Add routes, providers and Commands here.
	os.Exit(app.Main(os.Args[1:]))
}

With no arguments, the binary serves requests. With arguments, it runs the Command they name. The same binary therefore runs Commands in production, where act isn't installed:

Terminal
./blog about

List Commands

Run act alone, or act --help, to list the Commands, the App's own included:

Output
Run the App's Commands

Usage:
  act <command> [flags]

Commands:
  about            Describe the App: versions, Mode and what its providers configure
  generate:key     Generate a random APP_KEY and write it to .env
  posts:publish    Publish the posts scheduled until now
  completion       Print a shell completion script

Flags:
  -h, --help     Show help
      --json     Print a single JSON result instead of text
      --version  Print the version

Get help for a Command

Add --help after a Command's name, or put help before it, to see its arguments and flags:

Terminal
act posts:publish --help
act help posts:publish
Output
Publish the posts scheduled until now

Usage:
  act posts:publish [flags]

Flags:
      --limit int       Publish at most this many posts (default 100)
  -h, --help            Show help
      --json            Print a single JSON result instead of text
      --no-interaction  Never prompt; use defaults

A mistyped name fails with a suggestion:

Output
Error: unknown flag: --limt.
  Did you mean --limit?
  Fix: Run `act posts:publish --help` to see usage

act completion prints a script that completes Command names and flags when you press Tab. See Commands to load it.

Run Commands without prompts

A Command asks for what you didn't pass, such as a missing name, when you run it in a terminal. In scripts and CI, nobody can answer, so Commands never prompt there: they use defaults, and fail with an error naming the flag to pass when an answer is required. Pass --no-interaction to get the same behavior in a terminal:

Terminal
act make:controller posts --no-interaction

See Prompts for how Commands ask, and how each question maps to a flag.

Control colors

Commands use colors only when they write to a terminal. Set NO_COLOR to any value to turn them off, or use a terminal with TERM=dumb:

Terminal
NO_COLOR=1 act about

See also: Creating Commands, Commands reference, Agent mode