-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rs
More file actions
80 lines (69 loc) · 2.36 KB
/
cli.rs
File metadata and controls
80 lines (69 loc) · 2.36 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
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[clap(version = env!("CARGO_PKG_VERSION"))]
pub struct Cli {
#[command(subcommand)]
pub subcommand: Option<Subcommands>,
#[clap(long = "gh-token")]
#[arg(help = "GitHub token (can be specified multiple times)", global = true)]
pub gh_token: Vec<String>,
#[clap(long = "trunk-token", env = "TRUNK_TOKEN")]
#[arg(default_value_t = String::from(""), global = true)]
pub trunk_token: String,
#[clap(long = "dry-run")]
#[arg(default_value_t = false, global = true)]
pub dry_run: bool,
}
impl Cli {
/// Get all GitHub tokens (from CLI args and environment variable)
pub fn get_github_tokens(&self) -> Vec<String> {
let mut tokens = self.gh_token.clone();
// Add GH_TOKEN from environment if no CLI tokens provided
if tokens.is_empty() {
if let Ok(env_token) = std::env::var("GH_TOKEN") {
if !env_token.is_empty() {
tokens.push(env_token);
}
}
}
tokens
}
}
#[derive(Subcommand, Debug)]
pub enum Subcommands {
/// Generate default configuration content for generator
Defaultconfig,
/// Print configuration content to json, or a single value if path is provided (e.g., "trunk.api")
Config {
/// Optional path to a specific config value (e.g., "trunk.api")
#[arg(value_name = "PATH")]
path: Option<String>,
},
/// Clean out conflicting PRs and requeue failed PRs
Housekeeping,
/// Simulate a test with flake rate in consideration
TestSim,
/// Generate pull requests
Generate,
/// upload targets
UploadTargets(UploadTargets),
/// Enqueue a pull request
Enqueue(Enqueue),
}
#[derive(Parser, Debug)]
pub struct UploadTargets {
// Path to file that contains github-json block
#[clap(long = "github-json")]
pub github_json: String,
/// Optional: Path to JSON file containing array of targets to upload directly
/// If provided, targets will be read from this file instead of extracting from PR body
/// File should contain a JSON array: ["target1", "target2", "target3"]
#[clap(long = "targets-json")]
pub targets_json: Option<String>,
}
#[derive(Parser, Debug)]
pub struct Enqueue {
/// Pull request number to enqueue
#[clap(short, long)]
pub pr: String,
}