Sha256: ce0e2f72e7ea025f43e11f701e179bf04f8d0fdebd3c3ffeda6afc0d651a3e21

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require_relative '../command'

require "tty-font"
require "pastel"

module Dri
  module Commands
    class Init < Dri::Command
      def initialize(options)
        font = TTY::Font.new(:doom)       
        puts pastel.yellow(font.write("DRI"))
      end

      def execute(input: $stdin, output: $stdout)
        output.puts "🤖 Welcome to DRI 🤖\n"

        logger.info "🔎 Scanning for existing configurations...\n"

        if config.exist?
          overwrite = prompt.yes?("There is already a configuration initialized. Would you like to overwrite it?")
          unless overwrite
            output.puts "Using existing configuration. To view configuration in use try  #{add_color('dri profile', :yellow)}."
            exit 0
          end
        end

        @username = prompt.ask("What is your GitLab username?")
        @token = prompt.mask("Please provide your GitLab personal access token:")
        @timezone = prompt.select("Choose your current timezone?", %w(EMEA AMER APAC))
        @emoji = prompt.ask("Have a triage emoji?")

        if (@emoji || @token || @username).nil?
          logger.error "Please provide a username, token, timezone and emoji used for triage."
          exit 1
        end

        config.set(:settings, :user, value: @username)
        config.set(:settings, :token, value: @token)
        config.set(:settings, :timezone, value: @timezone)
        config.set(:settings, :emoji, value: @emoji)
        config.write(force: true)

        logger.success "✅ We're ready to go 🚀"      
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dri-0.1.1 lib/dri/commands/init.rb
dri-0.1.0 lib/dri/commands/init.rb