Module: PDK::CLI

Defined in:
lib/pdk.rb,
lib/pdk/cli.rb,
lib/pdk/cli/env.rb,
lib/pdk/cli/get.rb,
lib/pdk/cli/new.rb,
lib/pdk/cli/set.rb,
lib/pdk/cli/exec.rb,
lib/pdk/cli/test.rb,
lib/pdk/cli/util.rb,
lib/pdk/cli/build.rb,
lib/pdk/cli/bundle.rb,
lib/pdk/cli/errors.rb,
lib/pdk/cli/remove.rb,
lib/pdk/cli/update.rb,
lib/pdk/cli/console.rb,
lib/pdk/cli/convert.rb,
lib/pdk/cli/release.rb,
lib/pdk/cli/new/fact.rb,
lib/pdk/cli/new/task.rb,
lib/pdk/cli/new/test.rb,
lib/pdk/cli/validate.rb,
lib/pdk/cli/new/class.rb,
lib/pdk/cli/test/unit.rb,
lib/pdk/cli/exec_group.rb,
lib/pdk/cli/get/config.rb,
lib/pdk/cli/new/module.rb,
lib/pdk/cli/set/config.rb,
lib/pdk/cli/exec/command.rb,
lib/pdk/cli/new/function.rb,
lib/pdk/cli/new/provider.rb,
lib/pdk/cli/release/prep.rb,
lib/pdk/cli/new/transport.rb,
lib/pdk/cli/remove/config.rb,
lib/pdk/cli/util/interview.rb,
lib/pdk/cli/release/publish.rb,
lib/pdk/cli/new/defined_type.rb,
lib/pdk/cli/util/option_validator.rb,
lib/pdk/cli/util/option_normalizer.rb,
lib/pdk/cli/util/command_redirector.rb,
lib/pdk/cli/exec/interactive_command.rb,
lib/pdk/cli/util/update_manager_printer.rb

Overview

TODO: Refactor backend code to not raise CLI errors or use CLI util

methods.

Defined Under Namespace

Modules: Exec, Release, Remove, Set, Util Classes: ExecGroup, ExitWithError, FatalError, ParallelExecGroup, SerialExecGroup

Class Method Summary collapse

Class Method Details

.anonymised_argsObject

Attempt to anonymise the raw ARGV array if the command parsing failed.

If an item does not start with ‘-’ but is preceeded by an item that does start with ‘-’, assume that these items are an option/value pair and redact the value. Any additional values that do not start with ‘-’ that follow an option/value pair are assumed to be arguments (rather than subcommand names) and are also redacted.

Examples:

# Where PDK::CLI.args => ['new', 'plan', '--some', 'value', 'plan_name']

PDK::CLI.anonymised_args
  => ['new', 'plan', '--some', 'redacted', 'redacted']


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pdk/cli.rb', line 44

def self.anonymised_args
  in_args = false
  @args.map do |arg|
    if arg.start_with?('-')
      in_args = true
      arg
    else
      in_args ? 'redacted' : arg
    end
  end
end

.full_interview_option(dsl) ⇒ Object



97
98
99
# File 'lib/pdk/cli.rb', line 97

def self.full_interview_option(dsl)
  dsl.option nil, 'full-interview', 'When specified, interactive querying of metadata will include all optional questions.'
end

.puppet_dev_option(dsl) ⇒ Object



106
107
108
109
110
# File 'lib/pdk/cli.rb', line 106

def self.puppet_dev_option(dsl)
  dsl.option nil,
             'puppet-dev',
             'When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.'
end

.puppet_version_options(dsl) ⇒ Object



101
102
103
104
# File 'lib/pdk/cli.rb', line 101

def self.puppet_version_options(dsl)
  dsl.option nil, 'puppet-version', 'Puppet version to run tests or validations against.', argument: :required
  dsl.option nil, 'pe-version', '(Deprecated) Puppet Enterprise version to run tests or validations against.', argument: :required
end

.run(args) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pdk/cli.rb', line 56

def self.run(args)
  @args = args
  @base_cmd.run(args)
rescue PDK::CLI::ExitWithError => e
  PDK.logger.send(e.log_level, e.message)

  exit e.exit_code
rescue PDK::CLI::FatalError => e
  PDK.logger.fatal(e.message) if e.message

  # If FatalError was raised as the result of another exception, send the
  # details of that exception to the debug log. If there was no cause
  # (FatalError raised on its own outside a rescue block), send the details
  # of the FatalError exception to the debug log.
  cause = e.cause
  if cause.nil?
    e.backtrace.each { |line| PDK.logger.debug(line) }
  else
    PDK.logger.debug("#{cause.class}: #{cause.message}")
    cause.backtrace.each { |line| PDK.logger.debug(line) }
  end

  exit e.exit_code
end

.skip_interview_option(dsl) ⇒ Object



93
94
95
# File 'lib/pdk/cli.rb', line 93

def self.skip_interview_option(dsl)
  dsl.option nil, 'skip-interview', 'When specified, skips interactive querying of metadata.'
end

.template_ref_option(dsl) ⇒ Object



89
90
91
# File 'lib/pdk/cli.rb', line 89

def self.template_ref_option(dsl)
  dsl.option nil, 'template-ref', 'Specifies the template git branch or tag to use when creating new modules or classes.', argument: :required
end

.template_url_option(dsl) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/pdk/cli.rb', line 81

def self.template_url_option(dsl)
  require 'pdk/util/template_uri'

  desc = format('Specifies the URL to the template to use when creating new modules or classes. (default: %{default_url})', default_url: PDK::Util::TemplateURI.default_template_uri)

  dsl.option nil, 'template-url', desc, argument: :required
end