diff --git a/.gitignore b/.gitignore index 5a76fe4..f4d824d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ tmp coverage .rvmrc +.tddium* .solano* .solano-deploy-key* diff --git a/lib/solano/cli/commands/account.rb b/lib/solano/cli/commands/account.rb index 6ad0277..38fa152 100644 --- a/lib/solano/cli/commands/account.rb +++ b/lib/solano/cli/commands/account.rb @@ -1,8 +1,9 @@ -# Copyright (c) 2011, 2012, 2013, 2014 Solano Labs All Rights Reserved +# Copyright (c) 2011, 2012, 2013, 2014, 2015 Solano Labs All Rights Reserved module Solano class SolanoCli < Thor - desc "account", "View account information" + desc "account [--org NAME]", "View account information" + method_option :org, type: :string def account user_details = solano_setup({:scm => false}) diff --git a/lib/solano/cli/show.rb b/lib/solano/cli/show.rb index 41fec46..50de3dd 100644 --- a/lib/solano/cli/show.rb +++ b/lib/solano/cli/show.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2011, 2012, 2013, 2014 Solano Labs All Rights Reserved +# Copyright (c) 2011, 2012, 2013, 2014, 2015 Solano Labs All Rights Reserved module Solano class SolanoCli < Thor @@ -78,7 +78,21 @@ def show_user_details(user) # Use "all_accounts" here instead of "participating_accounts" -- these # are the accounts the user can administer. - user["all_accounts"].each do |acct| + # Select those accounts that match org param or all if no org param + + org = options['org'] + regexp = org.nil? ? nil : Regexp.new(org.to_s) + account_list = user['all_accounts'] + account_list.select! do |acct| + if regexp.nil? || regexp =~ acct[:account] then + acct + else + nil + end + end + account_list.compact! + + account_list.each do |acct| id = acct['account_id'].to_i say ERB.new(Text::Status::ACCOUNT_DETAILS).result(binding) diff --git a/lib/solano/util.rb b/lib/solano/util.rb index cbce84d..e36c5e7 100644 --- a/lib/solano/util.rb +++ b/lib/solano/util.rb @@ -1,4 +1,4 @@ -# Copyright (c) 2012, 2013, 2014 Solano Labs, Inc. All Rights Reserved +# Copyright (c) 2012, 2013, 2014, 2015 Solano Labs, Inc. All Rights Reserved require 'stringio' diff --git a/spec/cli/commands/account_spec.rb b/spec/cli/commands/account_spec.rb new file mode 100644 index 0000000..3e37bb7 --- /dev/null +++ b/spec/cli/commands/account_spec.rb @@ -0,0 +1,44 @@ +# Copyright (c) 2015 Solano Labs All Rights Reserved + +require 'spec_helper' +require 'solano/cli' +require 'solano/cli/commands/account' + +describe Solano::SolanoCli do + describe "#account" do + include_context 'solano_api_stubs' + + let(:data) do + { 'all_accounts' => [{ + "account_url"=>"http://localhost:3000/organizations/23/edit/profile", + "billing_type"=>"recurly", + "subscribed"=>false, + "trial_remaining"=>0, + "plan"=>"small", + "heroku_needs_activation"=>false, + "account"=>"some_name", + "account_id"=>23, + "account_role"=>"owner", + "account_owner"=>"anyzhnik@solanolabs.com" + }, + { "account_url"=>"http://localhost:3000/organizations/20/edit/profile", + "subscribed"=>false, + "trial_remaining"=>0, + "plan"=>"small", + "heroku_needs_activation"=>false, + "account"=>"some_other_name", + "account_id"=>20, + "account_role"=>"admin", + "account_owner"=>"nyzhnikandrii@gmail.com" + }] } + end + + before do + expect(subject).to receive(:solano_setup).with({ scm: false }).and_return(data) + expect(solano_api).to receive(:get_suites).and_return([]) + expect(solano_api).to receive(:get_memberships).and_return([]) + expect(solano_api).to receive(:get_usage).and_return({}) + ERB.any_instance.stub(:result) + end + end +end