From 500739a19425cebfe26f336d61ea30740fe7c61f Mon Sep 17 00:00:00 2001 From: Egor Tolstoy Date: Fri, 27 Oct 2017 18:40:06 +0300 Subject: [PATCH] Added organization subcommand --- bin/fabricio | 2 +- lib/fabricio/{ => cli}/cli.rb | 58 +++----------------------------- lib/fabricio/cli/cli_helper.rb | 46 +++++++++++++++++++++++++ lib/fabricio/cli/organization.rb | 21 ++++++++++++ 4 files changed, 72 insertions(+), 55 deletions(-) rename lib/fabricio/{ => cli}/cli.rb (55%) create mode 100644 lib/fabricio/cli/cli_helper.rb create mode 100644 lib/fabricio/cli/organization.rb diff --git a/bin/fabricio b/bin/fabricio index 724c30f..8e55b4f 100755 --- a/bin/fabricio +++ b/bin/fabricio @@ -1,4 +1,4 @@ #!/usr/bin/env ruby -require "fabricio/cli" +require "fabricio/cli/cli" Fabricio::CLI.start(ARGV) diff --git a/lib/fabricio/cli.rb b/lib/fabricio/cli/cli.rb similarity index 55% rename from lib/fabricio/cli.rb rename to lib/fabricio/cli/cli.rb index a082e99..0368c6d 100644 --- a/lib/fabricio/cli.rb +++ b/lib/fabricio/cli/cli.rb @@ -2,14 +2,14 @@ require 'fabricio' require 'fileutils' require 'yaml' +require_relative 'organization' +require_relative 'cli_helper' module Fabricio class CLI < Thor - # Constants - CREDENTIAL_DIRECTORY_PATH = "#{Dir.home}/.fabricio" - CREDENTIAL_FILE_PATH = "#{CREDENTIAL_DIRECTORY_PATH}/.credential" - FABRIC_GRAPHQL_API_URL = 'https://api-dash.fabric.io/graphql' + desc "organization", "..." + subcommand "organization", Organization desc "credential", "Setup credential" def credential @@ -32,17 +32,6 @@ def credential say("Complete!") end - desc "organization", "Obtain organization" - option :app_id => :required, :type => :string - option :short, :type => :boolean - def organization - if options[:short] - say(client.organization.get.pretty_print) - else - say("#{client.organization.get.to_s}") - end - end - desc "apps", "Obtain all app" option :short, :type => :boolean def apps @@ -90,44 +79,5 @@ def build(app_id, version, build_number) end end - private - def client - email = "" - password = "" - if File.file?(CREDENTIAL_FILE_PATH) - credential = YAML.load_file(CREDENTIAL_FILE_PATH) - email = credential['email'] - password = credential['password'] - else - ask_credential - end - - client = Fabricio::Client.new do |config| - config.username = email - config.password = password - end - end - - def create_credential_file(credential) - FileUtils.mkdir_p(CREDENTIAL_DIRECTORY_PATH) - credential_hash = { - "email" => credential.email, - "password" => credential.password - } - File.open(CREDENTIAL_FILE_PATH,'w') do |f| - f.write credential_hash.to_yaml - end - say("Your credential in #{CREDENTIAL_FILE_PATH}") - end - - def ask_credential - say("We have to know you're email from fabric account") - email = ask("email: ") - say("Now we want your password. Do not be afraid, it is stored locally") - password = ask("password: ", :echo => false) - say("") - Fabricio::Model::Credential.new(email, password) - end - end end diff --git a/lib/fabricio/cli/cli_helper.rb b/lib/fabricio/cli/cli_helper.rb new file mode 100644 index 0000000..03f91b5 --- /dev/null +++ b/lib/fabricio/cli/cli_helper.rb @@ -0,0 +1,46 @@ +require 'fabricio' +require 'fileutils' +require 'yaml' + +# Constants +CREDENTIAL_DIRECTORY_PATH = "#{Dir.home}/.fabricio" +CREDENTIAL_FILE_PATH = "#{CREDENTIAL_DIRECTORY_PATH}/.credential" +FABRIC_GRAPHQL_API_URL = 'https://api-dash.fabric.io/graphql' + +def client + email = "" + password = "" + if File.file?(CREDENTIAL_FILE_PATH) + credential = YAML.load_file(CREDENTIAL_FILE_PATH) + email = credential['email'] + password = credential['password'] + else + ask_credential + end + + client = Fabricio::Client.new do |config| + config.username = email + config.password = password + end +end + +def create_credential_file(credential) + FileUtils.mkdir_p(CREDENTIAL_DIRECTORY_PATH) + credential_hash = { + "email" => credential.email, + "password" => credential.password + } + File.open(CREDENTIAL_FILE_PATH,'w') do |f| + f.write credential_hash.to_yaml + end + say("Your credential in #{CREDENTIAL_FILE_PATH}") +end + +def ask_credential + say("We have to know you're email from fabric account") + email = ask("email: ") + say("Now we want your password. Do not be afraid, it is stored locally") + password = ask("password: ", :echo => false) + say("") + Fabricio::Model::Credential.new(email, password) +end \ No newline at end of file diff --git a/lib/fabricio/cli/organization.rb b/lib/fabricio/cli/organization.rb new file mode 100644 index 0000000..8cbd887 --- /dev/null +++ b/lib/fabricio/cli/organization.rb @@ -0,0 +1,21 @@ +require 'thor' +require 'fabricio' +require 'fileutils' +require 'yaml' +require_relative 'cli_helper' + +module Fabricio + class Organization < Thor + + desc "get", "Get organization" + option :short, :type => :boolean + def get + if options[:short] + say(client.organization.get.pretty_print) + else + say("#{client.organization.get.to_s}") + end + end + + end +end