• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkgxdev / pkgx / 13863219990

14 Mar 2025 06:39PM UTC coverage: 91.235%. First build
13863219990

Pull #1151

github

web-flow
Merge e39b8e6c8 into 35f6bbe1d
Pull Request #1151: --query,-Q

35 of 35 new or added lines in 4 files covered. (100.0%)

1374 of 1506 relevant lines covered (91.24%)

18538506.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.8
/crates/cli/src/args.rs
1
use console::style;
2

3
pub enum Mode {
4
    X,
5
    Help,
6
    Version,
7
    Query,
8
}
9

10
pub struct Flags {
11
    pub quiet: bool,
12
    pub silent: bool,
13
    pub json: bool,
14
    pub version_n_continue: bool,
15
    pub shebang: bool,
16
}
17

18
pub struct Args {
19
    pub plus: Vec<String>,
20
    pub args: Vec<String>,
21
    pub find_program: bool,
22
    pub mode: Mode,
23
    pub flags: Flags,
24
}
25

26
pub fn parse() -> Args {
36✔
27
    let mut mode = Mode::X;
36✔
28
    let mut plus = Vec::new();
36✔
29
    let mut args = Vec::new();
36✔
30
    let mut silent: bool = false;
36✔
31
    let mut quiet: bool = false;
36✔
32
    let mut json: bool = false;
36✔
33
    let mut find_program = false;
36✔
34
    let mut collecting_args = false;
36✔
35
    let mut version_n_continue = false;
36✔
36
    let mut shebang = false;
36✔
37

38
    for arg in std::env::args().skip(1) {
58✔
39
        if collecting_args {
58✔
40
            args.push(arg);
6✔
41
        } else if arg.starts_with('+') {
52✔
42
            plus.push(arg.trim_start_matches('+').to_string());
22✔
43
        } else if arg == "--" {
30✔
44
            find_program = false;
2✔
45
            collecting_args = true;
2✔
46
        } else if arg.starts_with("--") {
28✔
47
            match arg.as_str() {
14✔
48
                "--json" => {
14✔
49
                    if !silent {
2✔
50
                        eprintln!(
2✔
51
                            "{} use --json=v1",
2✔
52
                            style("warning: --json is not stable").yellow()
2✔
53
                        );
2✔
54
                    }
2✔
55
                    json = true
2✔
56
                }
57
                "--shebang" => shebang = true,
12✔
58
                "--json=v1" => json = true,
12✔
59
                "--silent" => silent = true,
10✔
60
                "--help" => mode = Mode::Help,
8✔
61
                "--version" => mode = Mode::Version,
6✔
62
                "--quiet" => quiet = true,
4✔
63
                "--query" => mode = Mode::Query,
2✔
64
                "--shellcode" => {
2✔
65
                    if !silent {
2✔
66
                        eprintln!("{}", style("⨯ migration required").red());
2✔
67
                        eprintln!(
2✔
68
                            "{} pkgx^2 is now exclusively focused on executing packages",
2✔
69
                            style("│").red()
2✔
70
                        );
2✔
71
                        eprintln!(
2✔
72
                            "{} you need to migrate to the new, isolated `dev` command",
2✔
73
                            style("│").red()
2✔
74
                        );
2✔
75
                        eprintln!("{} run the following:", style("│").red());
2✔
76
                        eprintln!(
2✔
77
                            "{} pkgx pkgx^1 deintegrate && pkgx dev integrate",
2✔
78
                            style("╰─➤").red()
2✔
79
                        );
2✔
80
                    }
2✔
81
                    std::process::exit(1);
2✔
82
                }
83
                _ => panic!("unknown argument {}", arg),
×
84
            }
85
        } else if arg.starts_with('-') {
14✔
86
            // spit arg into characters
87
            for c in arg.chars().skip(1) {
8✔
88
                match c {
8✔
89
                    'q' => {
90
                        if quiet {
×
91
                            silent = true
×
92
                        } else {
93
                            quiet = true
×
94
                        }
95
                    }
96
                    'h' => mode = Mode::Help,
×
97
                    's' => silent = true,
×
98
                    'j' => json = true,
2✔
99
                    'v' => version_n_continue = true,
2✔
100
                    '!' => shebang = true,
×
101
                    'Q' => mode = Mode::Query,
4✔
102
                    _ => panic!("unknown argument: -{}", c),
×
103
                }
104
            }
105
        } else {
6✔
106
            find_program = !arg.contains('/');
6✔
107
            collecting_args = true;
6✔
108
            args.push(arg);
6✔
109
        }
6✔
110
    }
111

112
    Args {
34✔
113
        plus,
34✔
114
        args,
34✔
115
        find_program,
34✔
116
        mode,
34✔
117
        flags: Flags {
34✔
118
            shebang,
34✔
119
            silent,
34✔
120
            json,
34✔
121
            quiet,
34✔
122
            version_n_continue,
34✔
123
        },
34✔
124
    }
34✔
125
}
34✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc