Class: Brut::CLI::Commands::ExecutionContext
- Inherits:
-
Object
- Object
- Brut::CLI::Commands::ExecutionContext
- 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
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#executor ⇒ Object
readonly
Returns the value of attribute executor.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Instance Method Summary collapse
-
#initialize(argv: :default, options: :default, env: :default, stdout: :default, stderr: :default, stdin: :default, executor: :default, logger: :default) ⇒ ExecutionContext
constructor
A new instance of ExecutionContext.
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 = == :default ? Brut::CLI::Options.new({}) : @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
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def argv @argv end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def env @env end |
#executor ⇒ Object (readonly)
Returns the value of attribute executor.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def executor @executor end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def @options end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
30 31 32 |
# File 'lib/brut/cli/commands/execution_context.rb', line 30 def stdout @stdout end |