Sha256: 4719342d933432424078feccfca357eb8e2c17448ad0b428623b2df216bf279b

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 Bytes

Contents

module PDK
  module CLI
    @new_class_cmd = @new_cmd.define_command do
      name 'class'
      usage 'class [options] <class_name>'
      summary 'Create a new class named <class_name> using given options'

      run do |opts, args, _cmd|
        require 'pdk/generate/puppet_class'

        PDK::CLI::Util.ensure_in_module!(
          message: 'Classes can only be created from inside a valid module directory.',
          log_level: :info
        )

        class_name = args[0]

        if class_name.nil? || class_name.empty?
          puts command.help
          exit 1
        end

        raise PDK::CLI::ExitWithError, format("'%{name}' is not a valid class name", name: class_name) unless Util::OptionValidator.valid_class_name?(class_name)

        updates = PDK::Generate::PuppetClass.new(PDK.context, class_name, opts).run
        PDK::CLI::Util::UpdateManagerPrinter.print_summary(updates, tense: :past)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pdk-3.4.0 lib/pdk/cli/new/class.rb
pdk-3.3.0 lib/pdk/cli/new/class.rb