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

pomsky-lang / pomsky / 12301483439

12 Dec 2024 05:19PM UTC coverage: 80.275% (-0.2%) from 80.471%
12301483439

push

github

Aloso
feat: test command

360 of 593 new or added lines in 11 files covered. (60.71%)

20 existing lines in 7 files now uncovered.

4607 of 5739 relevant lines covered (80.28%)

374427.68 hits per line

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

59.09
/pomsky-bin/src/args/help.rs
1
use helptext::{sections, Help, HelpSection};
2
use supports_color::Stream;
3

4
const USAGE: Help = Help(sections![
5
    "USAGE" {
6
        ["pomsky [OPTIONS] <INPUT>\n\
7
        pomsky [OPTIONS] --path <PATH>\n\
8
        command | pomsky [OPTIONS]"]
9
    }
10

11
    ["For more information try " c:"--help"]
12
]);
13

14
// Shared help message parts
15

16
const FLAVORS: &[HelpSection] = sections![
17
    table Compact {
18
        "pcre"       => { ["PCRE2 regex engines, compatible with Perl, PHP and R"] }
19
        "python"     => { ["Python's " c!"re" " module"] }
20
        "java"       => { ["Java's " c!"Pattern" " class, compatible with Kotlin and Scala"] }
21
        "javascript" => { ["ECMAScript regular expressions"] }
22
        "dotnet"     => { [c!"Regex" " class in .NET languages such C# and F#"] }
23
        "ruby"       => { ["Ruby's built-in regular expressions"] }
24
        "rust"       => { ["Rust's " c!"regex" " crate"] }
25
        "re2"        => { ["The RE2 engine, compatible with Go's " c!"regexp" " package"] }
26
    }
27
];
28

29
const ENGINES: &[HelpSection] = sections![
30
    table Compact {
31
        "pcre2"       => { ["PCRE2 regex engine, using the " c:"pcre" " flavor"] }
32
    }
33
];
34

35
const FEATURES: &[HelpSection] = sections! [
36
    table Compact {
37
        "ascii-mode"      => { ["Allows disabling Unicode mode globally with " g:"disable unicode;"] }
38
        "atomic-groups"   => { ["Allows atomic groups such as " g:"atomic('if' | 'else')"] }
39
        "boundaries"      => { ["Allows matching word boundaries and anchors " g:"%" ", " g:"!%" ", " g:"^" ", " g:"$"] }
40
        "dot"             => { ["Allows matching the dot " g:"."] }
41
        "grapheme"        => { ["Allows matching a grapheme cluster with " g:"Grapheme" " or " g:"G"] }
42
        "intersection"    => { ["Allows intersecting character sets with " g:"&"] }
43
        "lazy-mode"       => { ["Allows enabling lazy mode globally with " g:"enable lazy;"] }
44
        "lookahead"       => { ["Allows (negative) lookahead, e.g. " g:"(>> 'test')"] }
45
        "lookbehind"      => { ["Allows (negative) lookbehind, e.g. " g:"(<< 'test')"] }
46
        "named-groups"    => { ["Allows named capturing groups such as " g:":test('test')"] }
47
        "numbered-groups" => { ["Allows normal capturing groups such as " g:":('test')"] }
48
        "ranges"          => { ["Allows ranges, e.g. " g:"range '1'-'255'"]
49
                               [y!"warning" ": compiling ranges with many digits may be slow"] }
50
        "recursion"       => { ["Allows " g:"recursion"] }
51
        "references"      => { ["Allows referencing another capturing group, e.g. " g:"::2"] }
52
        "regexes"         => { ["Allows literal regular expressions, e.g. " g:"regex '[]^-]'"]
53
                               [y!"warning" ": does not guarantee that the output is well-formed"] }
54
        "variables"       => { ["Allows declaring variables, e.g. " g:"let num = ['0'-'9']+;"]
55
                               [y!"warning" ": compiling a lot of variables may be slow"] }
56
    }
57
];
58

59
const WARNINGS: &[HelpSection] = sections![
60
    Short ["Disable certain warnings (disable all with " c:"-W0" ")"]
61
    Long ["Disable some or all warnings. A single warning can be disabled by specifying
62
the name followed by " c:"=0" ", for example:
63

64
    " c!"-Wcompat=0" "
65

66
Multiple warnings can be disabled by setting this option multiple times, or
67
using a comma-separated list:
68

69
    " c!"-Wcompat=0 -Wdeprecated=0
70
    -Wcompat=0,deprecated=0" "
71

72
To disable all warnings, use " c:"-W0" ".
73

74
Currently, the following warnings can be disabled:"]
75
    Long table Compact {
76
        "compat"     => { ["Compatibility warnings"] }
77
        "deprecated" => { ["A used feature will be removed in the future"] }
78
    }
79
];
80

81
// Actual help messages
82

83
pub(super) const HELP: Help = Help(sections![
84
    [g!"pomsky " {env!("CARGO_PKG_VERSION")}]
85
    Long ["Home page: https://pomsky-lang.org"]
86
    ["\n\
87
    Compile pomsky expressions, a new regular expression language\n\
88
    \n\
89
    Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
90

91
    "USAGE" {
92
        ["pomsky [OPTIONS] <INPUT>\n\
93
        pomsky [OPTIONS] --path <PATH>\n\
94
        command | pomsky [OPTIONS]"]
95
    }
96

97
    "SUBCOMMANDS" {
98
        table Auto {
99
            "pomsky test" => {
100
                ["Run unit tests in pomsky expressions"]
101
                Long ["\n\
102
                Run " c:"pomsky test --help" " for more information"]
103
            }
104
        }
105
    }
106

107
    "ARGS" {
108
        table Auto {
109
            "<INPUT>" => {
110
                ["Pomsky expression to compile"]
111
                Long ["\n\
112
                To learn about the pomsky language, start here:\n\
113
                https://pomsky-lang.org/docs/"]
114
            }
115
        }
116
    }
117

118
    "OPTIONS" {
119
        table Auto {
120
            "    --allowed-features <FEATURE>..." => {
121
                ["Comma-separated list of allowed features [default: all enabled]"]
122
                Long ["Supported features are listed below."]
123
            }
124
            "-f, --flavor <FLAVOR>" => {
125
                ["Regex flavor [default: " c:"pcre" "]"]
126
                Long ["Supported flavors are listed below."]
127
            }
128
            "-h, --help" => {
129
                ["Print help information"]
130
                Long ["Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
131
            }
132
            "    --list shorthands" => {
133
                ["Show all available character class shorthands"]
134
            }
135
            "-n, --no-new-line" => {
136
                ["Don't print a new-line after the output"]
137
            }
138
            "-p, --path <FILE>" => {
139
                ["File containing the pomsky expression to compile"]
140
            }
141
            "-V, --version" => {
142
                ["Print version information"]
143
            }
144
            "-W, --warnings <DIAGNOSTICS>" => WARNINGS
145
            "-d, --debug" => {
146
                Long ["Show debug information"]
147
            }
148
            "    --json" => {
149
                Long ["Return output as JSON"]
150
            }
151
        }
152
    }
153

154
    Long "FLAVORS" FLAVORS
155
    Long "FEATURES" FEATURES
156
]);
157

158
pub(super) const TEST_HELP: Help = Help(sections![
159
    [g!"pomsky test " {env!("CARGO_PKG_VERSION")}]
160
    Long ["Home page: https://pomsky-lang.org"]
161
    ["\n\
162
    Test pomsky expressions, a new regular expression language\n\
163
    \n\
164
    Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
165

166
    "USAGE" {
167
        ["pomsky test [OPTIONS] --path <PATH>\n\
168
        pomsky test [OPTIONS] <INPUT>\n\
169
        command | pomsky test [OPTIONS]"]
170
    }
171

172
    "ARGS" {
173
        table Auto {
174
            "<INPUT>" => {
175
                ["Pomsky expression to test"]
176
                Long ["\n\
177
                To learn about the pomsky language, start here:\n\
178
                https://pomsky-lang.org/docs/"]
179
            }
180
        }
181
    }
182

183
    "OPTIONS" {
184
        table Auto {
185
            "    --allowed-features <FEATURE>..." => {
186
                ["Comma-separated list of allowed features [default: all enabled]"]
187
                Long ["Supported features are listed below."]
188
            }
189
            "-f, --flavor <FLAVOR>" => {
190
                ["Regex flavor"]
191
                Long ["Supported flavors are listed below."]
192
                Long ["If " c:"--engine" " is specified, the flavor can be omitted."]
193
            }
194
            "-e, --engine <ENGINE>" => {
195
                ["Regex engine used for testing"]
196
                Long ["If " c:"--flavor" " is specified, the engine can be omitted."]
197
            }
198
            "-h, --help" => {
199
                ["Print help information"]
200
                Long ["Use " c:"-h" " for short descriptions and " c:"--help" " for more details."]
201
            }
202
            "-p, --path <FILE>" => {
203
                ["File or directory containing the pomsky expressions to compile"]
204
                Long ["If a directory is specified, all contained " c:"*.pomsky" " files are tested.
205
Note that pomsky respects " c:".gitignore" " files."]
206
            }
207
            "    --pass-with-no-tests" => {
208
                ["Don't error if the specified directory contains no " c:"*.pomsky" " files"]
209
            }
210
            "-W, --warnings <DIAGNOSTICS>" => WARNINGS
211
            "    --json" => {
212
                Long ["Report test results as JSON"]
213
            }
214
        }
215
    }
216

217
    Long "FLAVORS" FLAVORS
218
    Long "ENGINES" ENGINES
219
    Long "FEATURES" FEATURES
220
]);
221

222
pub(crate) fn print_short_usage_and_help_err() {
8✔
223
    let _ = USAGE.write(&mut std::io::stderr().lock(), false, is_colored(Stream::Stderr));
8✔
224
}
8✔
225

226
pub(crate) fn print_short_help() {
1✔
227
    let _ = HELP.write(&mut std::io::stdout().lock(), false, is_colored(Stream::Stdout));
1✔
228
}
1✔
229

230
pub(crate) fn print_long_help() {
×
231
    let _ = HELP.write(&mut std::io::stdout().lock(), true, is_colored(Stream::Stdout));
×
232
}
×
233

NEW
234
pub(crate) fn print_test_short_help() {
×
NEW
235
    let _ = TEST_HELP.write(&mut std::io::stdout().lock(), false, is_colored(Stream::Stdout));
×
NEW
236
}
×
237

NEW
238
pub(crate) fn print_test_long_help() {
×
NEW
239
    let _ = TEST_HELP.write(&mut std::io::stdout().lock(), true, is_colored(Stream::Stdout));
×
NEW
240
}
×
241

242
fn is_colored(stream: Stream) -> bool {
9✔
243
    matches!(
1✔
244
        supports_color::on_cached(stream),
9✔
245
        Some(supports_color::ColorLevel { has_basic: true, .. })
246
    )
247
}
9✔
248

249
pub(crate) fn print_version() {
1✔
250
    println!(concat!("pomsky ", env!("CARGO_PKG_VERSION")));
1✔
251
}
1✔
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