Sha256: c7a4d5b30816b83c6515da1a3da3b45cba68ddbefd0f00279d312cc990fa2676

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

module CliTemplate
  class New < Sequence
    argument :project_name

    # Ugly, but when the class_option is only defined in the Thor::Group class
    # it doesnt show up with cli-template new help :(
    # If anyone knows how to fix this let me know.
    # Also options from the cli can be pass through to here
    def self.cli_options
      [
        [:repo, desc: "GitHub repo to use. Format: user/repo"],
        [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
        [:git, type: :boolean, default: true, desc: "Git initialize the project"],
        [:subcommand, type: :boolean, default: false, desc: "Include subcommand example"],
      ]
    end

    cli_options.each do |args|
      class_option *args
    end

    def create_project
      options[:repo] ? clone_project : copy_project

      destination_root = "#{Dir.pwd}/#{project_name}"
      self.destination_root = destination_root
      FileUtils.cd("#{Dir.pwd}/#{project_name}")
    end

    def make_executable
      chmod("exe", 0755 & ~File.umask, verbose: false) if File.exist?("exe")
    end

    def bundle_install
      Bundler.with_unbundled_env do
        system("BUNDLE_IGNORE_CONFIG=1 bundle install")
      end
    end

    def git_init
      return if !options[:git]
      return unless git_installed?
      return if File.exist?(".git") # this is a clone repo

      run("git init")
      run("git add .")
      run("git commit -m 'first commit'")
    end

    def user_message
      puts <<-EOL
#{"="*64}
Congrats 🎉 You have successfully created a CLI project.

Test the CLI:

  cd #{project_name}
  bundle
  exe/#{project_name} hello       # top-level commands
  bundle exec rspec

To publish your CLI as a gem:

  1. edit the #{project_name}.gemspec
  2. edit lib/#{project_name}/version.rb
  3. update the CHANGELOG.md

And run:

  rake release

EOL
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cli-template-4.0.2 lib/cli_template/new.rb