Sha256: dedb682c6019e920e46ac2f3745bc19014da2a400503a03bc91d0f4959f791f9

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 KB

Contents

require 'tty-prompt'

module PDK::CLI
  @module_generate_cmd = @module_cmd.define_command do
    name 'generate'
    usage _('generate [options] <module_name>')
    summary _('This command is now \'pdk new module\'.')

    PDK::CLI.template_url_option(self)
    PDK::CLI.skip_interview_option(self)

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

      module_name = args[0]

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

      PDK.logger.info(_('New modules are created using the ‘pdk new module’ command.'))
      prompt = TTY::Prompt.new(help_color: :cyan)
      redirect = PDK::CLI::Util::CommandRedirector.new(prompt)
      redirect.target_command('pdk new module')
      answer = redirect.run

      if answer
        module_name_parts = module_name.split('-', 2)
        if module_name_parts.size > 1
          opts[:username] = module_name_parts[0]
          opts[:module_name] = module_name_parts[1]
        else
          opts[:module_name] = module_name
        end
        opts[:target_dir] = opts[:module_name]

        PDK.logger.info(_('Creating new module: %{modname}') % { modname: module_name })
        PDK::Generate::Module.invoke(opts)
      else
        exit 1
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
pdk-akerl-1.9.1.1 lib/pdk/cli/module/generate.rb
pdk-1.9.1 lib/pdk/cli/module/generate.rb
pdk-1.9.0 lib/pdk/cli/module/generate.rb
pdk-akerl-1.8.0.1 lib/pdk/cli/module/generate.rb
pdk-1.8.0 lib/pdk/cli/module/generate.rb
pdk-1.7.1 lib/pdk/cli/module/generate.rb
pdk-1.7.0 lib/pdk/cli/module/generate.rb
pdk-1.6.1 lib/pdk/cli/module/generate.rb
pdk-1.6.0 lib/pdk/cli/module/generate.rb
pdk-1.5.0 lib/pdk/cli/module/generate.rb
pdk-1.4.1 lib/pdk/cli/module/generate.rb
pdk-1.3.2 lib/pdk/cli/module/generate.rb
pdk-1.3.1 lib/pdk/cli/module/generate.rb
pdk-1.3.0 lib/pdk/cli/module/generate.rb