@@ -14,6 +14,7 @@ priv struct CliOptions {
1414 exclude_dirs : Array [String ]
1515 verbose : Bool
1616 enable_builtin_rules : Bool
17+ no_color : Bool
1718}
1819
1920///|
@@ -161,6 +162,14 @@ fn cli_flag_enabled(flags : Map[String, Bool], name : String) -> Bool {
161162 }
162163}
163164
165+ ///|
166+ fn no_color_enabled(env : Map [String , String ]) -> Bool {
167+ match env.get("NO_COLOR ") {
168+ Some (value) if value == "1" => true
169+ _ => false
170+ }
171+ }
172+
164173///|
165174fn docs_cli_command(
166175 docs_matches : @argparse.Matches ,
@@ -206,12 +215,16 @@ fn dump_cli_command(
206215}
207216
208217///|
209- fn scan_cli_options(scan_matches : @argparse.Matches ) -> CliOptions raise {
218+ fn scan_cli_options(
219+ scan_matches : @argparse.Matches ,
220+ env : Map [String , String ],
221+ ) -> CliOptions raise {
210222 let verbose = cli_flag_enabled(scan_matches.flags, "verbose")
211223 let enable_builtin_rules = cli_flag_enabled(
212224 scan_matches.flags,
213225 "enable-builtin-rules",
214226 )
227+ let no_color = no_color_enabled(env)
215228 let rules_root = last_cli_value(scan_matches.values, "rules")
216229 let rule_file = last_cli_value(scan_matches.values, "rule")
217230 let patterns = all_cli_values(scan_matches.values, "pattern")
@@ -241,6 +254,7 @@ fn scan_cli_options(scan_matches : @argparse.Matches) -> CliOptions raise {
241254 exclude_dirs,
242255 verbose,
243256 enable_builtin_rules,
257+ no_color,
244258 }
245259}
246260
@@ -304,7 +318,7 @@ fn parse_cli_command(
304318 }
305319 match matches.subcommand {
306320 Some (("scan", scan_matches)) =>
307- ("scan", Some (scan_cli_options(scan_matches)), None )
321+ ("scan", Some (scan_cli_options(scan_matches, env )), None )
308322 Some (("docs", docs_matches)) => docs_cli_command(docs_matches)
309323 Some (("dump", dump_matches)) => dump_cli_command(dump_matches)
310324 _ => raise CliError ::Usage (message="missing required command", exit_code=2)
0 commit comments