//! Output for the command line: the ✦ / ✗ habit, and the `--json` shapes //! agents read. //! //! Colour comes from `src.fmt`, so turning it off turns it off everywhere. //! Every command that prints data has a JSON form with stable field names, and //! every error is `{"error": "..."}` on stderr. Exit codes are fixed: 0 //! success, 1 refusal or error, 2 bad usage. module cli import json import src.fmt pub fn ok(message string) { println(' ${fmt.amber(fmt.glyph_ok)} ${message}') } pub fn note(message string) { println(' ${fmt.dim(message)}') } pub fn warn(message string) { println(' ${fmt.amber('!')} ${message}') } // fail prints a refusal and returns the exit code to hand back. pub fn fail(message string) int { eprintln(' ${fmt.red(fmt.glyph_fail)} ${message}') return 1 } pub fn fail_json(message string) int { eprintln(json.encode({ 'error': message })) return 1 } pub fn usage_error(message string) int { eprintln(' ${fmt.red(fmt.glyph_fail)} ${message}') return 2 } // refuse reports an error in whichever shape the command was asked for. pub fn refuse(as_json bool, message string) int { if as_json { return fail_json(message) } return fail(message) } pub fn emit_json(value string) { println(value) }