Sha256: cf891bdecdd755472ac832ea14ba8b990e05102806ad20670f3ffeff85857094

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

require 'commander/blank'
require 'commander/command'

module PolyglotIos
  module Command
    class Projects
      include Helper::Terminal
      include Helper::General

      attr_accessor :options
      
      def self.init(options = Commander::Command::Options.new)
        new(options).call
      end
    
      def initialize(options = Commander::Command::Options.new)
        @options = options
      end

      def call
        list_projects
      end

      def filtered_projects
        projects
          .select { |key, _id| key[/^(.*?(#{option_query})[^$]*)$/i] }
          .sort_by { |p| p[0].downcase }
          .to_h
      end
    
      def projects
        prompt.say('Getting projects...')
        PolyglotIos::Resource::Project.token(token).depaginate.each_with_object({}) do |r, hash|
          hash[r.name] = r.id
        end
      end
    
      def option_query
        @option_query ||= @options.__hash__.fetch(:query, '')
      end

      private

      def list_projects
        projects = filtered_projects
        selection = projects
          .each_with_object({}) do |project, hash|
            project_name = project[0]
            project_id = project[1]
            display_name = "#{project_name} => #{project_id}"
            hash[display_name] = project_id
          end
        prompt.say("  Name - ID: \n  ----------")
        selected_id = prompt
          .select("", selection)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ios_polyglot_cli-2.4.0 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.3.0 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.2.2 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.2.1 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.2.0 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.1.1 lib/ios_polyglot_cli/commands/projects.rb
ios_polyglot_cli-2.1.0 lib/ios_polyglot_cli/commands/projects.rb