Sha256: 0e15fc484051af60ca615a93f96618dd9cda010b87e57e5747ba74784a2b56bf

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require "cp8_cli/config_store"

module Cp8Cli
  class GlobalConfig
    LEGACY_PATH = ENV["HOME"] + "/.trello_flow"
    PATH = ENV["HOME"] + "/.cp8_cli"

    def initialize(store = nil)
      @store = store || initialize_store
    end

    def github_token
      @_github_token ||= store[:github_token] || env_github_token || configure_github_token
    end

    private

      attr_reader :store

      def initialize_store
        migrate_legacy_store if uses_legacy_store?

        default_store
      end

      def uses_legacy_store?
        legacy_store.exist?
      end

      def migrate_legacy_store
        Command.say("#{LEGACY_PATH} was deprecated, moving to #{PATH}")
        legacy_store.move_to(PATH)
      end

      def default_store
        @_default_store ||= ConfigStore.new(PATH)
      end

      def legacy_store
        @_legacy_store ||= ConfigStore.new(LEGACY_PATH)
      end

      def env_github_token
        ENV["OCTOKIT_ACCESS_TOKEN"]
      end

      def configure_github_token
        store.save(
          :github_token,
          Command.ask("Input GitHub access token with repo access scope (https://github.com/settings/tokens):")
        )
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cp8_cli-9.1.1 lib/cp8_cli/global_config.rb
cp8_cli-9.1.0 lib/cp8_cli/global_config.rb