cmd_init.v

962 B · raw

1//! `koh init` — write the `.koh` file and a default ignore list.23module cli45import json6import os7import src.snapshot8import src.storage910pub fn cmd_init(raw []string) int {11	args := parse('init', raw, Options{12		flags: ['json']13	}) or { return usage_error(err.msg()) }14	root := os.getwd()15	store := storage.create(root) or { return refuse(args.json(), err.msg()) }16	store.close()17	ignore_path := os.join_path(root, snapshot.ignore_file)18	mut wrote_ignore := false19	if !os.exists(ignore_path) {20		os.write_file(ignore_path, snapshot.default_ignore) or {21			return refuse(args.json(), err.msg())22		}23		wrote_ignore = true24	}25	if args.json() {26		emit_json(json.encode(InitJson{27			repo:           root28			ignore_created: wrote_ignore29		}))30		return 031	}32	ok('initialised koh in ${root}')33	if wrote_ignore {34		note('wrote ${snapshot.ignore_file} — edit it to suit the project')35	}36	return 037}3839struct InitJson {40	repo           string41	ignore_created bool42}