class Analyzer::Kotlin::Cli

Overview

Surfaces the command-line attack surface of Kotlin programs as cli:// endpoints: one endpoint per (sub)command with named options (param_type "flag"), positional arguments ("argument") and consumed environment variables ("env"). Covers clikt, kotlinx-cli and picocli plus gated System.getenv reads.

Line-scan analyzer (Go/Ruby/Rust CLI house style) merging endpoints by URL. Subclasses Analyzer directly (KotlinEngine is a module) and uses KotlinEngine.test_path? to skip tests.

Defined in:

analyzer/analyzers/kotlin/cli.cr

Constant Summary

ARGPARSER = /\bArgParser\s*\(\s*"([^"]+)"/

kotlinx-cli.

CLIKT_ARG = /\bval\s+(\w+)\s+by\s+argument\s*\(/
CLIKT_CLASS = /\bclass\s+(\w+)\s*(?:\([^)]*\))?\s*:\s*[^{]*\bCliktCommand\b/

clikt: class Serve : CliktCommand(name = "serve") (name optional → class name lower-cased).

CLIKT_ENVVAR = /\benvvar\s*=\s*"([^"]+)"/
CLIKT_NAME = /CliktCommand\s*\([^)]*\bname\s*=\s*"([^"]+)"/
CLIKT_OPTION = /\bval\s+(\w+)\s+by\s+option\s*\(([^)]*)\)/
GET_ENV = /\bSystem\.getenv\s*\(\s*"([^"]+)"\s*\)/
KX_ARGUMENT = /\bby\s+\w*\.?argument\s*\(\s*ArgType\.\w+\s*,\s*"([^"]+)"/
KX_OPTION = /\bby\s+\w*\.?option\s*\(\s*ArgType\.\w+\s*,\s*"([^"]+)"/
LIBRARY_SIGNAL_RE = Regex.union(["com.github.ajalt.clikt", "kotlinx.cli", "picocli.CommandLine", /:\s*CliktCommand\b/, /\bArgParser\s*\(/] of Regex | String)

One precompiled Regex.union scan (PCRE2 JIT, auto-escapes each string literal) replaces the three library-marker String#includes? scans OR-ed with the CliktCommand/ArgParser regex fallback below — this gate runs once per Kotlin file in the scan.

PICOCLI_CLASS = /\bclass\s+(\w+)\b/
PICOCLI_COMMAND_START = /@Command\s*\(/

picocli: annotations sit on the line above the class/property they decorate (@Command(name = "serve") \n class Serve : Callable<Int>), so a one-line lookahead resolves each pending annotation. A @Command( may wrap across lines once description/subcommands are added, so the annotation start is matched with a bounded body-join instead of requiring the close paren on the same line.

PICOCLI_NAME = /\bname\s*=\s*"([^"]+)"/
PICOCLI_OPTION = /@Option\s*\(([^)]*)\)/
PICOCLI_PARAMS = /@Parameters\b/
PICOCLI_PROPERTY = /\b(?:var|val)\s+(\w+)\s*:/
WEB_FRAMEWORK_RE = /\bimport\s+(?:org\.springframework|io\.ktor|org\.http4k)/

Instance Method Summary

Instance methods inherited from class Analyzer

analyze analyze, base_path : String base_path, base_paths : Array(String) base_paths, callees_needed? : Bool callees_needed?, 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, 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

Instance methods inherited from module FileHelper

all_files : Array(String) all_files, 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_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

Instance Method Detail

def analyze #

[View source]