Class: Brut::CLI::Commands::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/brut/cli/commands/execution_context.rb

Overview

The context in which a command's execution is run. This holds essentially all values that are input to the command, including parsed command line options, unparsed arguments, the UNIX environment, and the three I/O streams (stderr, stdout, stdin).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv: :default, options: :default, env: :default, stdout: :default, stderr: :default, stdin: :default, executor: :default, logger: :default) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/brut/cli/commands/execution_context.rb', line 6

def initialize(
  argv: :default,
  options: :default,
  env: :default,
  stdout: :default,
  stderr: :default,
  stdin: :default,
  executor: :default,
  logger: :default
)
  @argv       =    argv == :default ? []                                                          : argv
  @options  =   options == :default ? Brut::CLI::Options.new({})                                  : options
  @env      =       env == :default ? {}                                                          : env
  @stdout   =    stdout == :default ? $stdout                                                     : stdout
  @stderr   =    stderr == :default ? $stderr                                                     : stderr
  @stdin    =     stdin == :default ? $stdin                                                      : stdin
  @logger   =    logger == :default ? Brut::CLI::Logger.new(app_name: $0, stdout: @stdout, stderr: @stderr) : logger
  @executor =  executor == :default ? Brut::CLI::Executor.new(logger: @logger, out: self.stdout, err: self.stderr) : executor

  @logger.level         = @options.log_level
  @logger.log_file      = @options.log_file
  @logger.log_to_stdout = @options.log_stdout?
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def argv
  @argv
end

#envObject (readonly)

Returns the value of attribute env.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def env
  @env
end

#executorObject (readonly)

Returns the value of attribute executor.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def executor
  @executor
end

#loggerObject (readonly)

Returns the value of attribute logger.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def options
  @options
end

#stderrObject (readonly)

Returns the value of attribute stderr.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



30
31
32
# File 'lib/brut/cli/commands/execution_context.rb', line 30

def stdout
  @stdout
end