summary refs log tree commit diff
path: root/ripple/fossil/src/bin/add.rs
blob: 84e67e25d8ce4e9ce5cbfe340511ac8e43f8b8e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-FileCopyrightText: edef <edef@unfathomable.blue>
// SPDX-License-Identifier: OSL-3.0

use {
	clap::StructOpt,
	fossil::Directory,
	prost::Message,
	std::{
		io::{self, Write},
		path::{Path, PathBuf},
	},
};

#[derive(clap::Parser)]
struct Args {
	#[clap(name = "PATH")]
	paths: Vec<PathBuf>,
	#[clap(long, default_value = "fossil.db")]
	store: PathBuf,
}

fn main() {
	let args = Args::parse();

	let store = fossil::Store::open(args.store).unwrap();
	let mut root = Directory::new();

	for name in args.paths {
		let path = Path::new(&name);
		let name = path
			.file_name()
			.and_then(|s| s.to_str())
			.expect("invalid path")
			.to_owned();

		root.children.insert(name, store.add_path(path));
	}

	let mut stdout = io::stdout();
	stdout.write_all(&root.into_pb().encode_to_vec()).unwrap();
}