class CliTemplate::Sequence

Public Class Methods

source_root() click to toggle source
# File lib/cli_template/sequence.rb, line 12
def self.source_root
  template = ENV['TEMPLATE'] || 'default'
  File.expand_path("../../templates/#{template}", __FILE__)
end

Private Instance Methods

clone_project() click to toggle source
# File lib/cli_template/sequence.rb, line 18
def clone_project
  unless git_installed?
    abort "Unable to detect git installation on your system.  Git needs to be installed in order to use the --repo option."
  end

  if File.exist?(project_name)
    abort "The folder #{project_name} already exists."
  else
    run "git clone https://github.com/#{options[:repo]} #{project_name}"
  end
  confirm_cli_project
end
confirm_cli_project() click to toggle source
# File lib/cli_template/sequence.rb, line 31
def confirm_cli_project
  cli_project = File.exist?("#{project_name}/config/application.rb")
  unless cli_project
    puts "It does not look like the repo #{options[:repo]} is a cli project. Maybe double check that it is?  Exited.".colorize(:red)
    exit 1
  end
end
copy_options() click to toggle source
# File lib/cli_template/sequence.rb, line 53
def copy_options
  excludes = if @options[:subcommand]
    []
  else
    %w[
      help/sub
      sub.rb
    ]
  end

  if excludes.empty?
    {}
  else
    pattern = Regexp.new(excludes.join('|'))
    {exclude_pattern: pattern }
  end
end
copy_project() click to toggle source
# File lib/cli_template/sequence.rb, line 39
  def copy_project
    puts "Creating new project called #{project_name}."
    directory ".", project_name, copy_options
    if project_name.include?("-")
      dashed_path = "#{project_name}/lib/#{project_name}.rb"
      underscored_path = "#{project_name}/lib/#{underscored_name}.rb"

      FileUtils.mv(dashed_path, underscored_path)
      IO.write(dashed_path, <<~EOL)
        require_relative "#{underscored_name}"
      EOL
    end
  end
git_installed?() click to toggle source
# File lib/cli_template/sequence.rb, line 71
def git_installed?
  system("type git > /dev/null")
end