1use std::{ffi, path};
2use structopt::{clap, StructOpt};
3
4#[derive(StructOpt)]
6pub struct Options {
7 #[structopt(flatten)]
8 pub command: Command,
9}
10
11#[derive(StructOpt)]
12pub struct BaseOptions {
13 #[structopt(
15 short = "-d",
16 long = "--base-dir",
17 env = "GIT_PROJECT_BASE_DIR",
18 parse(try_from_os_str = "parse_canonical_path")
19 )]
20 pub base_dir: path::PathBuf,
21}
22
23#[derive(StructOpt)]
24pub enum Command {
25 #[structopt(name = "clone")]
27 Clone(CloneOptions),
28
29 #[structopt(name = "list")]
31 List(ListOptions),
32
33 #[structopt(name = "check")]
35 Check(CheckOptions),
36
37 #[structopt(name = "organize")]
39 Organize(OrganizeOptions),
40
41 #[structopt(name = "gen-completions")]
43 GenCompletions(CompletionOptions),
44}
45
46#[derive(StructOpt)]
47pub struct CloneOptions {
48 #[structopt(flatten)]
49 pub base: BaseOptions,
50
51 #[structopt(short = "-n", long = "--dry-run")]
53 pub only_print_location: bool,
54
55 #[structopt(name = "URL")]
57 pub clone_url: String,
58}
59
60#[derive(StructOpt)]
61pub struct ListOptions {
62 #[structopt(flatten)]
63 pub base: BaseOptions,
64
65 #[structopt(flatten)]
66 pub list: BaseListOptions,
67}
68
69#[derive(StructOpt)]
70pub struct BaseListOptions {
71 #[structopt(short = "-r", long = "--deep-recurse")]
73 pub deep_recurse: bool,
74}
75
76#[derive(StructOpt)]
77pub struct CheckOptions {
78 #[structopt(flatten)]
79 pub list: BaseListOptions,
80
81 #[structopt(flatten)]
82 pub base: BaseOptions,
83
84 #[structopt(short = "-s", long = "--summarize")]
86 pub summarize: bool,
87}
88
89#[derive(StructOpt)]
90pub struct OrganizeOptions {
91 #[structopt(name = "DIR", parse(from_os_str))]
93 pub dir: path::PathBuf,
94
95 #[structopt(name = "NEW_DIR", parse(from_os_str))]
97 pub new_dir: path::PathBuf,
98
99 #[structopt(short = "-n", long = "--dry-run")]
101 pub dry_run: bool,
102}
103
104#[derive(StructOpt)]
105pub struct CompletionOptions {
106 #[structopt(
108 name = "SHELL",
109 raw(
110 possible_values = "&clap::Shell::variants()",
111 case_insensitive = "true"
112 )
113 )]
114 pub shell: clap::Shell,
115}
116
117fn parse_canonical_path(path_str: &ffi::OsStr) -> Result<path::PathBuf, ffi::OsString> {
118 path::Path::new(path_str).canonicalize().map_err(|err| {
119 ffi::OsString::from(format!(
120 "Unable to recognize base directory as absolute path: {}",
121 err
122 ))
123 })
124}