Class: Cliqr::Interface Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/interface.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The execution interface to a command line application built using Cliqr

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Interface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new interface instance with a config

Parameters:



21
22
23
24
# File 'lib/cliqr/interface.rb', line 21

def initialize(config)
  @config = config
  @runner = Executor::Runner.new(config)
end

Instance Attribute Details

#configCliqr::CLI::Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Command line interface configuration

Returns:

  • (Cliqr::CLI::Config)


16
17
18
# File 'lib/cliqr/interface.rb', line 16

def config
  @config
end

Class Method Details

.build(config) ⇒ Cliqr::CLI::Interface

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Invoke the builder method for [Cliqr::CLI::Interface]

Parameters:

  • config (Cliqr::CLI::Config)

    Instance of the command line config

Returns:

  • (Cliqr::CLI::Interface)


63
64
65
# File 'lib/cliqr/interface.rb', line 63

def self.build(config)
  InterfaceBuilder.new(config).build
end

Instance Method Details

#execute(args = [], **options) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute a command

Parameters:

  • args (Array<String>) (defaults to: [])

    Arguments that will be used to execute the command

  • options (Hash)

    Options for command execution

Returns:

  • (Integer)

    Exit code of the command execution



39
40
41
42
43
44
45
# File 'lib/cliqr/interface.rb', line 39

def execute(args = [], **options)
  execute_internal(args, options)
  Executor::ExitCode.code(:success)
rescue Cliqr::Error::CliqrError => e
  puts e.message
  Executor::ExitCode.code(e)
end

#execute_internal(args = [], **options) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes a command without handling error conditions

Returns:

  • (Integer)

    Exit code



50
51
52
53
54
55
56
# File 'lib/cliqr/interface.rb', line 50

def execute_internal(args = [], **options)
  options = {
      :output => :default,
      :environment => :cli
  }.merge(options)
  @runner.execute(args, options)
end

#usageString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get usage information of this command line interface instance

Returns:

  • (String)

    Defines usage of this interface



29
30
31
# File 'lib/cliqr/interface.rb', line 29

def usage
  Usage::UsageBuilder.new(:cli).build(config)
end