summary refs log tree commit diff
path: root/ripple/fossil/src/bin/add.rs
blob: 776836615e6c620b0d6df76c23531f637e596be5 (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
// 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>,
}

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

	let store = fossil::Store::open("fossil.db").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();
}