cli.v

1.0 KB · raw

1//! Command line entry: dispatch table, usage text and exit codes.2//!3//! Exit codes are fixed across every command: 0 success, 1 refusal or error,4//! 2 bad usage. Each command returns its code; nothing else calls `exit`.56module cli78// Read from VERSION at build time, so the binary and the manifest cannot drift.9pub const version = $embed_file('../../VERSION').to_string().trim_space()1011const usage = 'koh ${version} — one SQLite file per repo, one line of history1213usage: koh <command> [options]1415  save, checkpoint, status, log, diff16  undo, revert, load17  flag, pluck, peek18  offer, steal, remote19  init, doctor, strip, migrate2021run "koh help <command>" for one command\'s options.'2223pub fn run(args []string) int {24	if args.len < 2 {25		eprintln(usage)26		return 227	}28	match args[1] {29		'--version', '-v' {30			println('koh ${version}')31			return 032		}33		'--help', '-h', 'help' {34			println(usage)35			return 036		}37		else {38			eprintln('koh: unknown command "${args[1]}"')39			eprintln('run "koh --help" for the command list')40			return 241		}42	}43}