Command line
This guide covers Tinka's command line. You will learn how to:
- Run Commands with
act - List Commands and read their help
- Run Commands from the App's binary, where
actisn't installed - Run Commands in scripts and CI without prompts
- Control colors
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:
act posts:publish --limit 5Inside 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:
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:
./blog aboutList Commands
Run act alone, or act --help, to list the Commands, the App's own included:
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 versionGet help for a Command
Add --help after a Command's name, or put help before it, to see its arguments and flags:
act posts:publish --help
act help posts:publishPublish 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 defaultsA mistyped name fails with a suggestion:
Error: unknown flag: --limt.
Did you mean --limit?
Fix: Run `act posts:publish --help` to see usageact 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:
act make:controller posts --no-interactionSee 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:
NO_COLOR=1 act aboutSee also: Creating Commands, Commands reference, Agent mode