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 s/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) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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
)
  @argv     =                             argv == :default ? []                                                          : argv
  @options  =                          options == :default ? Brut::CLI::Options.new({})                                  : options
  @env      =                              env == :default ? {}                                                          : env
  @stdout   = Brut::CLI::Output.from_io(stdout == :default ? $stdout                                                     : stdout)
  @stderr   = Brut::CLI::Output.from_io(stderr == :default ? $stderr                                                     : stderr)
  @stdin    =                            stdin == :default ? $stdin                                                      : stdin
  @executor =                         executor == :default ? Brut::CLI::Executor.new(out: self.stdout, err: self.stderr) : executor
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def argv
  @argv
end

#envObject (readonly)

Returns the value of attribute env.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def env
  @env
end

#executorObject (readonly)

Returns the value of attribute executor.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def executor
  @executor
end

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def options
  @options
end

#stderrObject (readonly)

Returns the value of attribute stderr.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def stderr
  @stderr
end

#stdinObject (readonly)

Returns the value of attribute stdin.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



24
25
26
# File 'lib/brut/cli/commands/execution_context.rb', line 24

def stdout
  @stdout
end