~sircmpwn/hare unlisted

2b5fde226458613c1226410fadeb9bede06e6563 — Drew DeVault 2 months ago c34cc1d
cmd/hare: rework 'hare version' command

Signed-off-by: Drew DeVault <sir@cmpwn.com>
1 files changed, 28 insertions(+), 12 deletions(-)

M cmd/hare/subcmds.ha
M cmd/hare/subcmds.ha => cmd/hare/subcmds.ha +28 -12
@@ 399,19 399,35 @@ fn test(args: []str) void = {
};

fn version(args: []str) void = {
	fmt::printfln("Hare version {}", VERSION)!;
	fmt::errorln()!;
	fmt::printf("Build tags\t")!;
	const tags = default_tags();
	for (let i = 0z; i < len(tags); i += 1) {
		const tag = tags[i];
		const inclusive = (tag.mode & module::tag_mode::INCLUSIVE) == module::tag_mode::INCLUSIVE;
		fmt::printf("{}{}", if (inclusive) '+' else '-', tag.name)!;
	const help: []getopt::help = [
		"provides version information for the Hare environment",
		('v', "print more information"),
	];
	const cmd = getopt::parse(args, help...);
	defer getopt::finish(&cmd);

	let verbose = false;
	for (let i = 0z; i < len(cmd.opts); i += 1) {
		// The only option is verbose
		verbose = true;
	};
	fmt::println()!;

	match (os::getenv("HAREPATH")) {
		void => fmt::printfln("HAREPATH\t{}", HAREPATH)!,
		s: str => fmt::printfln("HAREPATH\t{}\t(from environment)", s)!,
	fmt::printfln("Hare {}", VERSION)!;

	if (verbose) {
		fmt::errorln()!;
		fmt::printf("Build tags\t")!;
		const tags = default_tags();
		for (let i = 0z; i < len(tags); i += 1) {
			const tag = tags[i];
			const inclusive = (tag.mode & module::tag_mode::INCLUSIVE) == 0;
			fmt::printf("{}{}", if (inclusive) '+' else '-', tag.name)!;
		};
		fmt::println()!;

		match (os::getenv("HAREPATH")) {
			void => fmt::printfln("HAREPATH\t{}", HAREPATH)!,
			s: str => fmt::printfln("HAREPATH\t{}\t(from environment)", s)!,
		};
	};
};