github.com/charypar/monobuild@v0.0.0-20211122220434-fd884ed50212/rs/src/cli.rs (about) 1 use structopt::StructOpt; 2 3 #[derive(Debug)] 4 pub enum Source { 5 Stdin, 6 Git, 7 } 8 9 /// A build orchestration tool for Continuous Integration in a monorepo. 10 /// 11 /// Read a graph of dependencies in a monorepo codebase (where separate 12 /// components live side by side) and decide what should be built, given the git 13 /// history. 14 #[derive(StructOpt, Debug)] 15 #[structopt(name = "monobuild", rename_all = "kebab", no_version)] 16 pub struct Opts { 17 #[structopt(subcommand, no_version)] 18 pub cmd: Command, 19 } 20 21 #[derive(StructOpt, Debug)] 22 pub struct InputOpts { 23 /// Search pattern for depenency files 24 #[structopt(long = "dependency-files", default_value = "**/Dependencies")] 25 pub dependency_files_glob: String, 26 27 /// Full manifest file (as produced by 'print --full') 28 #[structopt(short = "f", long = "file")] 29 pub full_manifest: Option<String>, 30 } 31 32 #[derive(StructOpt, Debug)] 33 pub struct OutputOpts { 34 /// Ouput the dependencies, not the build schedule 35 #[structopt(long)] 36 pub dependencies: bool, 37 38 /// Print in DOT format for GraphViz 39 #[structopt(long)] 40 pub dot: bool, 41 42 /// Print the full dependency graph including strengths 43 #[structopt(long)] 44 pub full: bool, 45 46 /// Scope output to single component and its dependencies 47 #[structopt(long)] 48 pub scope: Option<String>, 49 50 /// Only list top-level components that nothing depends on 51 #[structopt(long)] 52 pub top_level: bool, 53 } 54 55 #[derive(StructOpt, Debug)] 56 pub struct DiffOpts { 57 /// "Base branch to use o comparison" 58 #[structopt(long, default_value = "master")] 59 pub base_branch: String, 60 61 /// Base commit to compare with (useful in main-branch mode when using rebase merging) 62 #[structopt(long, default_value = "HEAD^1")] 63 pub base_commit: String, 64 65 /// Run in main branch mode (i.e. only compare with parent commit) 66 #[structopt(long)] 67 pub main_branch: bool, 68 69 /// Include all strong dependencies of affected components 70 #[structopt(long)] 71 pub rebuild_strong: bool, 72 73 // FIXME this seems really hacky, there's got to be a better way 74 /// Read changed files from STDIN 75 #[structopt(name = "-", default_value = "", parse(from_str = parse_stdin))] 76 pub changes: Source, 77 78 #[structopt(flatten)] 79 pub input_opts: InputOpts, 80 #[structopt(flatten)] 81 pub output_opts: OutputOpts, 82 } 83 84 #[derive(StructOpt, Debug)] 85 pub struct PrintOpts { 86 #[structopt(flatten)] 87 pub input_opts: InputOpts, 88 #[structopt(flatten)] 89 pub output_opts: OutputOpts, 90 } 91 92 #[derive(StructOpt, Debug)] 93 pub enum Command { 94 /// Build schedule for components affected by git changes 95 /// 96 /// Create a build schedule based on git history and dependency graph. 97 /// Each line in the output is a component and its dependencies. 98 /// The format of each line is: 99 /// 100 /// <component>: <dependency>, <dependency>, <dependency>, ... 101 /// 102 /// Diff can output either the build schedule (using only strong dependencies) or 103 /// the original dependeny graph (using all dependencies). 104 /// 105 /// By default changed files are determined from the local git repository. 106 /// Optionally, they can be provided externaly from stdin, by adding a hypen (-) after 107 /// the diff command. 108 #[structopt(no_version)] 109 Diff(DiffOpts), 110 /// Print the full build schedule or dependency graph 111 /// 112 /// Print the full build schedule or dependency graph based on the manifest files. 113 /// The format of each line is: 114 /// 115 /// <component>: <dependency>, <dependency>, <dependency>, ... 116 /// 117 /// Diff can output either the build schedule (using only strong dependencies) or 118 /// the original dependeny graph (using all dependencies). 119 #[structopt(no_version)] 120 Print(PrintOpts), 121 } 122 123 fn parse_stdin(src: &str) -> Source { 124 if src == "-" { 125 Source::Stdin 126 } else { 127 Source::Git 128 } 129 }