Sha256: 939bac191733fe9a2e9a1f11195de3fde9345571cf7a4b536de13b9ba8c6d501

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

#!ruby
# frozen_string_literal: true

require 'thor'
require 'gitignore'
require 'tty-prompt'

module Gitignore
  class CLI < Thor
    desc 'list', 'list all environment options'
    def list
      formatted_envs = Gitignore.list.map { |env| " - #{env}\n" }.join('')

      puts <<~OUTPUT
        Available Environments:
        #{formatted_envs}

        Now you can generate your .gitignore file using choosed envs:
          $ gitignore generate vim ruby node > .gitignore
      OUTPUT
    end

    desc 'generate', 'generate a .gitignore and print to STDOUT'
    def generate(*envs)
      puts Gitignore.generate(envs)
    end

    desc 'create', 'generate a .gitignore file using a interactive term ui'
    option :out, type: :string, default: '.gitignore', desc: 'OUTPUT_FILE'
    def create
      prompt = TTY::Prompt.new(interrupt: :exit)

      prompt.on(:keyescape) do
        exit
      end

      env_list = Gitignore.list
      results = prompt.multi_select(
        'Select envs to generate the .gitignore?', env_list, filter: true
      )

      unless results.any?
        puts 'No environment selected... exiting!'
        exit
      end

      file = File.open(options[:out], 'w')
      file.write(Gitignore.generate(results))
      file.close

      puts 'The .gitignore is generated!'
    end
  end
end

Gitignore::CLI.start(ARGV)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitignore-cli-0.11.0 bin/gitignore