-
Notifications
You must be signed in to change notification settings - Fork 17
Add list command #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list command #14
Changes from all commits
3332d86
31a5d51
f54ce8d
db7dfd4
447795a
52a5cc3
99ea0a5
38577a1
252e94f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,15 @@ module Github::Auth | |
| class CLI | ||
| attr_reader :command, :usernames | ||
|
|
||
| COMMANDS = %w(add remove) | ||
| COMMANDS = %w(add remove list) | ||
|
|
||
| def initialize(argv) | ||
| @command = argv.shift | ||
| @usernames = argv | ||
| end | ||
|
|
||
| def execute | ||
| if COMMANDS.include?(command) && !usernames.empty? | ||
| if COMMANDS.include?(command) | ||
| send command | ||
| elsif command == '--version' | ||
| print_version | ||
|
|
@@ -23,15 +23,29 @@ def execute | |
| private | ||
|
|
||
| def add | ||
| if usernames.empty? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm kind of bummed we have to to check
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a plan 👍 |
||
| print_usage | ||
| return | ||
| end | ||
|
|
||
| on_keys_file :write!, | ||
| "Adding #{keys.count} key(s) to '#{keys_file.path}'" | ||
| end | ||
|
|
||
| def remove | ||
| if usernames.empty? | ||
| print_usage | ||
| return | ||
| end | ||
|
|
||
| on_keys_file :delete!, | ||
| "Removing #{keys.count} key(s) from '#{keys_file.path}'" | ||
| end | ||
|
|
||
| def list | ||
| puts "Added users: #{keys_file.github_users.join(', ')}" | ||
| end | ||
|
|
||
| def on_keys_file(action, message) | ||
| puts message | ||
| rescue_keys_file_errors { keys_file.send action, keys } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| require 'stringio' | ||
|
|
||
| def capture_stdout | ||
| captured_output = StringIO.new | ||
| real_stdout = $stdout | ||
| $stdout = captured_output | ||
| yield | ||
| captured_output.string | ||
| ensure | ||
| $stdout = real_stdout | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for updating the docs too. 🎉