compiler/front/commands

    Dark Mode
Search:
  Source   Edit

This module handles the parsing of command line arguments.

Types

CliEvent = object
  srcCodeOrigin*: InstantiationInfo
  pass*: TCmdLinePass
  case kind*: CliEventKind
  of cliEvtErrInvalidCommand, cliEvtErrCmdExpectedNoAdditionalArgs,
     cliEvtErrUnexpectedRunOpt:
      cmd*: string
      unexpectedArgs*: string

  of cliEvtErrFlagArgForbidden, cliEvtErrFlagArgExpectedFromList,
     cliEvtErrFlagArgNotFromValidList:
      flag*: CliFlagKind
      givenFlg*: string
      givenArg*: string

  of cliEvtErrRunCmdFailed, cliEvtErrGenDependFailed:
      shellCmd*: string
      exitCode*: int

  of cliEvtErrFlagProcessing, cliEvtWarnSwitchValDeprecatedNoop:
      origParseOptKey*, origParseOptVal*: string
      procResult*: ProcSwitchResult

  of cliEvtHintPathAdded:
      pathAdded*: string

  of cliEvtErrNoCliParamsProvided, cliEvtErrCmdMissing:
      nil

  
  Source   Edit
CliEventKind = enum
  cliEvtErrInvalidCommand, cliEvtErrCmdMissing, cliEvtErrCmdExpectedNoAdditionalArgs, ## flag disallows additional args
  cliEvtErrFlagArgExpectedFromList, ## flag expected arg from an allow/valid list, but got none
  cliEvtErrFlagArgNotFromValidList, ## flag expects arg from an allow/valid list
  cliEvtErrRunCmdFailed, cliEvtErrGenDependFailed, cliEvtErrUnexpectedRunOpt,
  cliEvtErrFlagArgForbidden, cliEvtErrFlagProcessing,
  cliEvtErrNoCliParamsProvided, cliEvtWarnSwitchValDeprecatedNoop, cliEvtHintPathAdded ## currently only triggered if nimble adds a path
  Source   Edit
CliFlagKind = enum
  cliFlagVersion, cliFlagHelp, cliFlagHelpFull, cliFlagHelpAdvanced,
  cliFlagMsgFormat
list of cli only flags   Source   Edit
CmdOutputKind = enum
  cmdOutUser,               ## a command's primary output, e.g. dump's data dump
  cmdOutStatus,             ## command's status, e.g. build success message
  cmdOutUserProf,           ## user requested profiling output
  cmdOutInternalDbg          ## explicitly secondary output for compiler tracing
  Source   Edit

Procs

proc cliEventLogger(conf: ConfigRef; evt: CliEvent) {.
    ...raises: [ValueError, IOError], tags: [WriteIOEffect].}
a basic event logger that will write to standard err/out as appropriate and follow conf settings.   Source   Edit
func cliFmt(conf: ConfigRef; info: TLineInfo; useColor: bool): string {.
    ...raises: [ValueError], tags: [].}
  Source   Edit
func cliFmtLineInfo(filename: string; line, col: int; useColor: bool): string {.
    ...raises: [ValueError], tags: [].}
  Source   Edit
func cliFmtMsgOrigin(origin: InstantiationInfo; showSuffix, useColor: bool): string {.
    ...raises: [ValueError], tags: [].}
  Source   Edit
func cliFmtSrcCodeOrigin(origin: InstantiationInfo; useColor: bool): string {.
    ...raises: [ValueError], tags: [].}
  Source   Edit
proc logError(conf: ConfigRef; evt: CliEvent) {....raises: [ValueError, IOError],
    tags: [WriteIOEffect].}
  Source   Edit
proc logError(conf: ConfigRef; msg: string; srcLoc = instLoc()) {.
    ...raises: [ValueError, IOError], tags: [WriteIOEffect].}
logs and error message, typically this means writing to console, and bumps the error counter in ConfigRef to ensure a non-zero exit code.   Source   Edit
proc logExecStart(conf: ConfigRef; cmd: string; srcLoc = instLoc()) {.
    ...raises: [ValueError, IOError], tags: [WriteIOEffect].}
use when a command invocation begins a shell exec as part of its operations; not currently meant for shell execs initiated by input source code or scripts.   Source   Edit
proc logGcStats(conf: ConfigRef; stats: string; srcLoc = instLoc()) {.
    ...raises: [ValueError, IOError], tags: [WriteIOEffect].}
log a 'debug' level message with the GC stats   Source   Edit
proc processArgument(pass: TCmdLinePass; p: OptParser; argsCount: var int;
                     config: ConfigRef): bool {....raises: [], tags: [].}
  Source   Edit
proc processCmdLine(pass: TCmdLinePass; cmd: openArray[string];
                    config: ConfigRef) {....raises: [ValueError, IOError,
    Exception, OSError, KeyError, ERecoverableError, EOFError], tags: [
    WriteIOEffect, RootEffect, ReadEnvEffect, ReadIOEffect, ReadDirEffect,
    WriteDirEffect, WriteEnvEffect].}
Process input command-line parameters into config settings. Input is a joined list of command-line arguments with multiple options and/or configurations.   Source   Edit
proc showMsg(conf: ConfigRef; msg: string) {....raises: [IOError],
    tags: [WriteIOEffect].}

show a message to the user, meant for informational/status cirucmstances. Depending upon settings the message might not necessarily be output.

For command output, eg: dump's conditionals and search paths use a different routine (not implemented at time or writing).

  Source   Edit
func stylize(str: string; color: ForegroundColor; style: Style): string {.
    inline, ...raises: [ValueError], tags: [].}
  Source   Edit
func stylize(str: string; color: ForegroundColor; styles: set[Style] = {}): string {.
    ...raises: [ValueError], tags: [].}
  Source   Edit
proc write(conf: ConfigRef; dest: static[CmdOutputKind]; msg: string)
  Source   Edit
proc writeln(conf: ConfigRef; dest: static[CmdOutputKind]; msg: string)
  Source   Edit
proc writeUsage(conf: ConfigRef) {....raises: [IOError], tags: [WriteIOEffect].}
  Source   Edit

Iterators

iterator procSwitchResultToEvents(conf: ConfigRef; pass: TCmdLinePass;
                                  origParseOptKey, origParseOptVal: string;
                                  r: ProcSwitchResult): CliEvent {....raises: [],
    tags: [].}
  Source   Edit