From ced028ddf172ae940fb8e3e9fa65d0f2bdfcf81a Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Sun, 8 Jan 2012 18:42:33 -0800 Subject: [PATCH] Remove interactive setup. --- lib/ghi.rb | 26 ++++++++++++-------------- spec/ghi_spec.rb | 29 ----------------------------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/lib/ghi.rb b/lib/ghi.rb index 4bf9aea..5e28b3a 100644 --- a/lib/ghi.rb +++ b/lib/ghi.rb @@ -10,13 +10,10 @@ def login return @login if defined? @login @login = `git config --get github.user`.chomp if @login.empty? - begin - print "Please enter your GitHub username: " - @login = gets.chomp - valid = user? @login - warn "invalid username" unless valid - end until valid - `git config --global github.user #@login` + warn "Please configure your GitHub username." + puts + puts "E.g., git config --global github.user [your username]" + abort end @login end @@ -25,13 +22,14 @@ def token return @token if defined? @token @token = `git config --get github.token`.chomp if @token.empty? - begin - print "GitHub token (https://github.com/account): " - @token = gets.chomp - valid = token? @token - warn "invalid token for #{login}" unless valid - end until valid - `git config --global github.token #@token` + warn "Please configure your GitHub token." + puts + puts "E.g., git config --global github.user [your token]" + puts + puts "Find your token here: https://github.com/account/admin" + abort + elsif @token.sub!(/^!/, '') + @token = `#@token` end @token end diff --git a/spec/ghi_spec.rb b/spec/ghi_spec.rb index 39f7e25..f25d829 100644 --- a/spec/ghi_spec.rb +++ b/spec/ghi_spec.rb @@ -59,33 +59,4 @@ GHI.should_receive(:`).once.and_return "da39a3ee5e6b4b0d3255bfef95601890\n" GHI.token.should == "da39a3ee5e6b4b0d3255bfef95601890" end - - it "should approve login input" do - GHI.instance_eval { instance_variable_defined?(:@login).should == false } - GHI.should_receive(:`).with("git config --get github.user"). - and_return "\n" - GHI.should_receive(:print).twice - GHI.should_receive(:gets).twice.and_return "defunct\n", "defunkt\n" - Net::HTTP.should_receive(:get).and_return "500: invalid: response", - LOGGED_OUT_YAML - GHI.should_receive(:warn).once - GHI.should_receive(:`).with("git config --global github.user defunkt"). - and_return "\n" - GHI.login.should == "defunkt" - end - - it "should approve token input" do - GHI.instance_eval { instance_variable_defined?(:@token).should == false } - GHI.stub!(:login).and_return "defunkt" - GHI.should_receive(:`).with("git config --get github.token"). - and_return "\n" - GHI.should_receive(:print).twice - token = "da39a3ee5e6b4b0d3255bfef95601890" - GHI.should_receive(:gets).and_return "invalid\n", "#{token}\n" - Net::HTTP.should_receive(:get).and_return LOGGED_OUT_YAML, LOGGED_IN_YAML - GHI.should_receive(:warn).once - GHI.should_receive(:`).with("git config --global github.token #{token}"). - and_return "\n" - GHI.token.should == token - end end