Sha256: 8c2fe79fe190b63667e9243069e862f2d41d595aeba67cd362d7ee0e84062236

Contents?: true

Size: 1.35 KB

Versions: 10

Compression:

Stored size: 1.35 KB

Contents

# encoding: utf-8

require 'pathname'
require_relative 'renderer'
require 'inspec/base_cli'

module Init
  class CLI < Inspec::BaseCLI
    namespace 'init'

    # TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed
    def self.banner(command, _namespace = nil, _subcommand = false)
      "#{basename} #{subcommand_prefix} #{command.usage}"
    end

    def self.subcommand_prefix
      namespace
    end

    # Look in the 'template' directory, and register a subcommand
    # for each template directory found there.
    template_dir = File.join(File.dirname(__FILE__), 'templates')
    Dir.glob(File.join(template_dir, '*')) do |template|
      template_name = Pathname.new(template).relative_path_from(Pathname.new(template_dir)).to_s

      # register command for the template
      desc "#{template_name} NAME", "Create a new #{template_name}"
      option :overwrite, type: :boolean, default: false,
        desc: 'Overwrites existing directory'
      define_method template_name.to_sym do |name_for_new_structure|
        renderer = Init::Renderer.new(self, options)
        renderer.render_with_values(template_name, name: name_for_new_structure)
      end
    end
  end

  # register the subcommand to Inspec CLI registry
  Inspec::Plugins::CLI.add_subcommand(Init::CLI, 'init', 'init TEMPLATE ...', 'Scaffolds a new project', {})
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
inspec-core-2.2.102 lib/bundles/inspec-init/cli.rb
inspec-2.2.102 lib/bundles/inspec-init/cli.rb
inspec-core-2.2.101 lib/bundles/inspec-init/cli.rb
inspec-2.2.101 lib/bundles/inspec-init/cli.rb
inspec-core-2.2.78 lib/bundles/inspec-init/cli.rb
inspec-2.2.78 lib/bundles/inspec-init/cli.rb
inspec-core-2.2.70 lib/bundles/inspec-init/cli.rb
inspec-2.2.70 lib/bundles/inspec-init/cli.rb
inspec-core-2.2.64 lib/bundles/inspec-init/cli.rb
inspec-2.2.64 lib/bundles/inspec-init/cli.rb