diff options
| author | diogo464 <[email protected]> | 2025-08-08 19:15:34 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-08 19:15:34 +0100 |
| commit | d2f1850fec1a5738badb3b9e6368f1c7698b35c6 (patch) | |
| tree | d2b484d4c7641b3e9908b0766c5d3b0ac836a4d0 | |
| parent | b0a6b4604899dbbe500cdc8e2b3cab9bf7d8f197 (diff) | |
improved view subcommand
| -rw-r--r-- | fctdrive/src/main.rs | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/fctdrive/src/main.rs b/fctdrive/src/main.rs index 91e5046..1dea4f2 100644 --- a/fctdrive/src/main.rs +++ b/fctdrive/src/main.rs | |||
| @@ -724,7 +724,12 @@ struct RenameArgs { | |||
| 724 | } | 724 | } |
| 725 | 725 | ||
| 726 | #[derive(Debug, Args)] | 726 | #[derive(Debug, Args)] |
| 727 | struct ViewArgs {} | 727 | struct ViewArgs { |
| 728 | #[clap(short, long)] | ||
| 729 | recursive: bool, | ||
| 730 | |||
| 731 | path: Option<DrivePath>, | ||
| 732 | } | ||
| 728 | 733 | ||
| 729 | #[derive(Debug, Args)] | 734 | #[derive(Debug, Args)] |
| 730 | struct ImportArgs { | 735 | struct ImportArgs { |
| @@ -857,16 +862,36 @@ fn cmd_view(args: ViewArgs) { | |||
| 857 | let mut fs = Fs::default(); | 862 | let mut fs = Fs::default(); |
| 858 | let ops = read_log_file(); | 863 | let ops = read_log_file(); |
| 859 | ops.iter().for_each(|op| apply(&mut fs, op).unwrap()); | 864 | ops.iter().for_each(|op| apply(&mut fs, op).unwrap()); |
| 860 | write_node(&mut writer, &fs, fs.root, Default::default()); | 865 | let node_id = match args.path { |
| 866 | Some(path) => find_node(&fs, &path), | ||
| 867 | None => Some(fs.root), | ||
| 868 | }; | ||
| 869 | if let Some(node_id) = node_id { | ||
| 870 | write_node( | ||
| 871 | &mut writer, | ||
| 872 | &fs, | ||
| 873 | node_id, | ||
| 874 | Default::default(), | ||
| 875 | args.recursive, | ||
| 876 | true, | ||
| 877 | ); | ||
| 878 | } | ||
| 861 | writer.flush().unwrap(); | 879 | writer.flush().unwrap(); |
| 862 | std::process::exit(0); | 880 | std::process::exit(0); |
| 863 | } | 881 | } |
| 864 | 882 | ||
| 865 | fn write_node(writer: &mut FsNodeWriter, fs: &Fs, node_id: FsNodeId, path: DrivePath) { | 883 | fn write_node( |
| 884 | writer: &mut FsNodeWriter, | ||
| 885 | fs: &Fs, | ||
| 886 | node_id: FsNodeId, | ||
| 887 | path: DrivePath, | ||
| 888 | recursive: bool, | ||
| 889 | recurse: bool, | ||
| 890 | ) { | ||
| 866 | let node = &fs.nodes[node_id]; | 891 | let node = &fs.nodes[node_id]; |
| 867 | match node.kind { | 892 | match node.kind { |
| 868 | FsNodeKind::File => { | 893 | FsNodeKind::File => { |
| 869 | write!( | 894 | writeln!( |
| 870 | writer, | 895 | writer, |
| 871 | "{}\tfile\t{}\t{}\t{}", | 896 | "{}\tfile\t{}\t{}\t{}", |
| 872 | path, node.lastmod, node.blob, node.author | 897 | path, node.lastmod, node.blob, node.author |
| @@ -874,15 +899,17 @@ fn write_node(writer: &mut FsNodeWriter, fs: &Fs, node_id: FsNodeId, path: Drive | |||
| 874 | .unwrap(); | 899 | .unwrap(); |
| 875 | } | 900 | } |
| 876 | FsNodeKind::Directory => { | 901 | FsNodeKind::Directory => { |
| 877 | write!( | 902 | writeln!( |
| 878 | writer, | 903 | writer, |
| 879 | "{}\tdir\t{}\t-\t{}", | 904 | "{}\tdir\t{}\t-\t{}", |
| 880 | path, node.lastmod, node.author | 905 | path, node.lastmod, node.author |
| 881 | ) | 906 | ) |
| 882 | .unwrap(); | 907 | .unwrap(); |
| 883 | for (child_comp, child_id) in node.children.iter() { | 908 | if recursive || recurse { |
| 884 | let child_path = path.push(child_comp.clone()); | 909 | for (child_comp, child_id) in node.children.iter() { |
| 885 | write_node(writer, fs, *child_id, child_path); | 910 | let child_path = path.push(child_comp.clone()); |
| 911 | write_node(writer, fs, *child_id, child_path, recursive, false); | ||
| 912 | } | ||
| 886 | } | 913 | } |
| 887 | } | 914 | } |
| 888 | } | 915 | } |
