Sha256: aadf69b94829d4367f6e957da67cfacc670ec270622376a2e9e0e8ef59a20d85

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require 'credentials_manager/version'
require 'commander'

module CredentialsManager
  class CLI
    include Commander::Methods

    # Parses command options and executes actions
    def run
      program :name, 'CredentialsManager'
      program :version, ::CredentialsManager::VERSION
      program :description, 'Manage credentials for fastlane tools.'

      # Command to add entry to Keychain
      command :add do |c|
        c.syntax = 'fastlane-credentials add'
        c.description = 'Adds a fastlane credential to the keychain.'

        c.option '--username username', String, 'Username to add.'
        c.option '--password password', String, 'Password to add.'

        c.action do |args, options|
          username = options.username || ask('Username: ')
          password = options.password || ask('Password: ') { |q| q.echo = '*' }

          add(username, password)

          puts "Credential #{username}:#{'*' * password.length} added to keychain."
        end
      end

      # Command to remove credential from Keychain
      command :remove do |c|
        c.syntax = 'fastlane-credentials remove'
        c.description = 'Removes a fastlane credential from the keychain.'

        c.option '--username username', String, 'Username to remove.'

        c.action do |args, options|
          username = options.username || ask('Username: ')

          remove(username)
        end
      end

      run!
    end

    private

    # Add entry to Apple Keychain using AccountManager
    def add(username, password)
      CredentialsManager::AccountManager.new(
        user: username,
        password: password
      ).add_to_keychain
    end

    # Remove entry from Apple Keychain using AccountManager
    def remove(username)
      CredentialsManager::AccountManager.new(
        user: username
      ).remove_from_keychain
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
credentials_manager-0.16.4 lib/credentials_manager/cli.rb
credentials_manager-1.0.0 lib/credentials_manager/cli.rb
credentials_manager-0.15.1 lib/credentials_manager/cli.rb
credentials_manager-0.15.0 lib/credentials_manager/cli.rb
credentials_manager-0.14.0 lib/credentials_manager/cli.rb