Skip to content

Commit

Permalink
Added organization subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
etolstoy committed Oct 27, 2017
1 parent b045d90 commit 500739a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bin/fabricio
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
require "fabricio/cli"
require "fabricio/cli/cli"

Fabricio::CLI.start(ARGV)
58 changes: 4 additions & 54 deletions lib/fabricio/cli.rb → lib/fabricio/cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
46 changes: 46 additions & 0 deletions lib/fabricio/cli/cli_helper.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions lib/fabricio/cli/organization.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 500739a

Please sign in to comment.