class
Analyzer::Haskell::Cli
- Analyzer::Haskell::Cli
- Analyzer
- Reference
- Object
Overview
Surfaces the command-line attack surface of Haskell programs as cli://
endpoints: optparse-applicative (long/argument/command), turtle
(Turtle.Options: optText/optInt/optPath/switch/arg/argText) plus getEnv
reads. Line-scan, merged by URL.
Included Modules
Defined in:
analyzer/analyzers/haskell/cli.crConstant Summary
-
ARGUMENT =
/(?<![A-Za-z0-9_'])argument\b.*?\bmetavar\s+"([A-Za-z0-9][\w-]*)"/ -
COMMAND =
/(?<![A-Za-z0-9_'])command\s+"([A-Za-z0-9][\w-]*)"/ -
GET_ENV =
/(?<![A-Za-z0-9_'])(?:getEnv|lookupEnv)\s+"([A-Za-z0-9_]\w*)"/ -
LONG =
/(?<![A-Za-z0-9_'])long\s+"([A-Za-z0-9][\w-]*)"/ -
MARKERS =
/\bimport\s+(?:qualified\s+)?Options\.Applicative\b|\b(?:execParser|strOption|subparser|hsubparser)\b|\bimport\s+(?:qualified\s+)?System\.Console\.(?:GetOpt|CmdArgs)\b|\bgetArgs\b|#{TURTLE_MARKERS}/ -
TEST_PATH_RE =
Regex.union("/test/", "_spec.") -
Per-path test-file gate. A precompiled
Regex.union(PCRE2 JIT) replaces the two OR-edString#includes?scans it used to run -- provably equivalent since union auto-escapes each literal, and a single regex pass overloweris cheaper than two substring scans. -
TURTLE_ARG =
/(?<![A-Za-z0-9_'])arg(?:Text|Int|Integer|Double|Read|Path)\s+"([A-Za-z0-9][\w-]*)"/ -
argText plus the type-suffixed positional combinators, mirroring the TURTLE_OPT alternation above.
-
TURTLE_ARG_FN =
/(?<![A-Za-z0-9_'])arg\s+(?:[A-Za-z_][\w.']*|\([^()]*\))\s+"([A-Za-z0-9][\w-]*)"\s+"[^"]*"/ -
arg(the generic reader-based combinator) is an even more common bare word thanswitch(ordinary local variables/parameters are routinely namedarg). Real usage is alwaysarg <reader> "name" "desc": the reader is an identifier/qualified-name or a parenthesized expression, and BOTH the name and description string literals are required -- a strayf arg x "str"call/comment only has one trailing string and won't match. -
TURTLE_MARKERS =
/\bimport\s+(?:qualified\s+)?Turtle\.Options\b|\bimport\s+(?:qualified\s+)?Turtle\b\s*\([^)]*\boptions\b[^)]*\)/ -
Turtle re-exports Turtle.Options from the top-level Turtle module, which is used pervasively for plain shell scripting too, so gate on either the qualified submodule import or an explicit
optionsname in the unqualified import list, never a bareimport Turtle. -
TURTLE_OPT =
/(?<![A-Za-z0-9_'])opt(?:Text|Int|Integer|Double|Path|Read|Bool)\s+"([A-Za-z0-9][\w-]*)"/ -
Turtle.Options: optText/optInt/optPath/... and switch take the flag name as their own first quoted argument (no
long "..."wrapper), so these need dedicated regexes distinct from LONG above. -
TURTLE_SWITCH =
/(?<![A-Za-z0-9_'])switch\s+"([A-Za-z0-9][\w-]*)"\s+'.'\s+"[^"]*"/ -
switchis a bare, extremely common Haskell identifier (also used by optparse-applicative itself, and as a plain string-pattern dispatch function). Real Turtle usage is always the full 3-argument shapeswitch "name" 'c' "desc"; require the trailing short-char + description so we don't fire on unrelatedswitch "x" = ...equations. -
WEB_RE =
/\bimport\s+(?:qualified\s+)?(?:Web\.Scotty|Servant|Yesod|Network\.Wai)\b/
Class Method Summary
Instance Method Summary
- #analyze
-
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class Analyzer
analyze
analyze,
base_path : String
base_path,
base_paths : Array(String)
base_paths,
base_relative_path(path : String) : String
base_relative_path,
callees_needed? : Bool
callees_needed?,
content_matches?(content : String, markers : Regex) : Bool
content_matches?,
http_header_name(name : String) : String | Nil
http_header_name,
line_number_for_index(content : String, char_index : Int32) : Int32
line_number_for_index,
logger : NoirLogger
logger,
parallel_analyze(files : Array(String), &block : String -> Nil)
parallel_analyze,
read_file_content(path : String) : String
read_file_content,
result : Array(Endpoint)
result,
tech : String
tech,
unique_params(params : Array(Param)) : Array(Param)
unique_params,
url : String
url,
web_root_path(path : String, markers : Array(String)) : String
web_root_path
Constructor methods inherited from class Analyzer
new(options : Hash(String, YAML::Any))
new
Macros inherited from class Analyzer
analyzer_for(tech)
analyzer_for
Instance methods inherited from module FileHelper
all_files : Array(String)
all_files,
get_files_by_basename(basename : String) : Array(String)
get_files_by_basename,
get_files_by_extension(extension : String) : Array(String)
get_files_by_extension,
get_files_by_extensions(extensions : Array(String)) : Array(String)
get_files_by_extensions,
get_files_by_prefix(prefix : String) : Array(String)
get_files_by_prefix,
get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String)
get_files_by_prefix_and_extension,
get_files_by_relative_path(relative_path : String, root : String = "") : Array(String)
get_files_by_relative_path,
get_public_dir_files(base_path : String, folder : String) : Array(String)
get_public_dir_files,
get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String)
get_public_files,
walked_path(expanded : String) : String
walked_path
Class Method Detail
Instance Method Detail
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.