-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
144 lines (138 loc) · 4.46 KB
/
Copy pathmain.rs
File metadata and controls
144 lines (138 loc) · 4.46 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use clap::{Parser as ClapParser, Subcommand};
pub mod diagnostics;
pub mod parser;
pub mod reader;
mod analyser;
mod command;
mod formatter;
mod table;
/// Top-level CLI for 'definition'
#[derive(ClapParser)]
#[command(name = "definition")]
#[command(version = "1.0")]
#[command(about = "Manage definitions, reports, and features")]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Assemble the definitions by running the producers that own them.
Poll {
/// Optional path to the collector config.
#[arg(short, long)]
config: Option<String>,
/// Optional path to the assembled output directory.
#[arg(short, long)]
out: Option<String>,
/// Optional subset of the configured sources to poll.
#[clap(short = 'n', long, value_parser, num_args = 1.., value_delimiter = ' ')]
only: Option<Vec<String>>,
/// Should keep the checkouts instead of deleting them, false on default
#[arg(short, long, default_value_t = false)]
keep: bool,
},
/// Generate a general report.
Report {
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
},
/// Generate a report for a or all module(s).
Module {
/// Optional name of the definition set.
#[arg(short, long)]
name: Option<String>,
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
},
/// Look up a specific definition.
Search {
/// Required name of the definition.
#[arg(short, long)]
name: String,
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
},
/// Watch for changes to and regenerate error reports.
Watch {
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
/// Should ignore warnings, true on default
#[arg(short, long, default_value_t = false)]
ignore_warnings: bool,
},
Push {
/// Runtime Token for Sagittarius.
#[arg(short, long)]
token: String,
/// URL to Sagittarius.
#[arg(short, long)]
url: String,
/// Optional Version for all definitions
#[arg(short, long)]
version: Option<String>,
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
},
Publish {
// Version field for all definitons
#[arg(short, long)]
version: String,
/// Optional path to root directory of all definitions.
#[arg(short, long)]
path: Option<String>,
/// Optional path to generated output directory.
#[arg(short, long)]
out: Option<String>,
/// Instead of writing one file per definition, write a single
/// compact `<module>.json` file per module containing the full
/// Module protobuf message.
#[arg(short, long, default_value_t = false)]
compact: bool,
},
Download {
#[arg(short, long)]
tag: Option<String>,
#[clap(short, long, value_parser, num_args = 1.., value_delimiter = ' ')]
features: Option<Vec<String>>,
},
}
#[tokio::main]
async fn main() {
let cli = Cli::parse();
match cli.command {
Commands::Poll {
config,
out,
only,
keep,
} => command::poll::poll(config, out, only, keep),
Commands::Report { path } => command::report::report_errors(path),
Commands::Module { name, path } => command::search_module::search_module(name, path),
Commands::Search { name, path } => command::search::search_definition(name, path),
Commands::Download { tag, features } => {
command::download::handle_download(tag, features).await
}
Commands::Watch {
path,
ignore_warnings,
} => command::watch::watch_for_changes(path, !ignore_warnings).await,
Commands::Push {
token,
url,
version,
path,
} => command::push::push(token, url, version, path).await,
Commands::Publish {
version,
path,
out,
compact,
} => command::publish::publish(version, path, out, compact).await,
}
}