Sha256: 956d582b6550fc62fb3c37e86556fa6e31e97a2d44a50adc1b0b62f9fb2ef705

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require 'gl/cli/registry'
require 'gl/cli/merge_requests'
require 'gl/cli/issues'

module Gl
  class CLI < Thor
    desc 'registry', 'registry'
    subcommand 'registry', Registry

    desc 'mr', 'merge requests'
    subcommand 'mr', MergeRequests

    desc 'issues', 'issues'
    subcommand 'issues', Issues

    def self.setup
      prompt = TTY::Prompt.new

      endpoint = `git config --get gitlab.endpoint`.chomp
      if endpoint.empty?
        endpoint = prompt.ask('Please enter the GitLab endpoint', default: 'https://gitlab.com')
        endpoint = "#{endpoint}/api/v4"

        if prompt.yes?("Do you want to persist #{endpoint} as gitlab.endpoint to your git config")
          `git config --global --add gitlab.endpoint #{endpoint}`
        end
      end

      token = `git config --get gitlab.token`.chomp
      if token.empty?
        token = prompt.mask('Please enter your GitLab token')

        if prompt.yes?('Do you want to persist the tokee as gitlab.token to your git config')
          `git config --global --add gitlab.token #{token}`
        end
      end

      Gitlab.endpoint = endpoint
      Gitlab.private_token = token
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gl-0.1.0 lib/gl/cli.rb