Skip to content

Commit

Permalink
rubyforgood#812 Add '-h' option to print help.
Browse files Browse the repository at this point in the history
  • Loading branch information
keithrbennett committed Sep 28, 2020
1 parent 4dcdfdf commit 170114d
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions bin/login
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/usr/bin/env ruby

# This script simplifies login for experimentation with the users added to the application when it is seeded
# in development mode.
#
# It outputs the available users and accepts a numbered choice. It then logs in as that choice,
# at the URL appropriate for that user.
#
# The browser window remains open as long as the script has not yet terminated (using Ctrl-C).
# You can either keep a terminal with this script open, or you can send it to the background with Ctrl-Z.
# If the latter, when you are finished using the browser, you can bring the script back to the foreground with `fg[Enter]`.
#
# Usage: `bin/login` from the project root
# See HELP_TEXT below for description.

require 'webdrivers'
require 'capybara/dsl'
Expand All @@ -36,23 +26,41 @@ class LoginExecutor
User.new('[email protected]', ALL_CASA_ADMIN_LOGIN_URL),
]

HELP_TEXT = <<~HEREDOC
Usage: bin/login [user_number]
This script automates login for experimentation with the users added to the application when it is seeded
in development mode.
If executed without any arguments, it outputs the available users and accepts a numbered choice.
It then logs in as that choice, at the URL appropriate for that user.
It can also be executed with the user list element number passed as an argument, to bypass interactive mode.
The browser window remains open as long as the script has not yet terminated (using Ctrl-C).
You can either keep a terminal with this script open, or you can send it to the background with Ctrl-Z.
If the latter, when you are finished using the browser, you can bring the script back to the foreground with `fg[Enter]`.
HEREDOC
def self.login
self.new.call
end
def call
if ARGV.first == '-h'
puts HELP_TEXT
exit 0
end
user = ARGV.empty? ? get_user_from_input : get_user_from_arg
puts "\nLogging in to #{user.url} as #{user.email}...\n\n"
visit_and_log_in(user)

loop do
puts "\n\nPress Ctrl-C to exit and close browser.\n\n"
puts "You can also press Ctrl-Z to send this to the background to continue using your terminal."
puts "When you are done, type fg[Enter] and then Ctrl-C."
$stdin.gets
end
print_post_open_message_and_wait
end
Expand Down Expand Up @@ -90,6 +98,23 @@ class LoginExecutor
USERS[choice - 1]
end
def print_post_open_message_and_wait
loop do
puts <<~HEREDOC
--------------------------------------------------------------------------------
Press Ctrl-C to exit and close browser.
You can also press Ctrl-Z to send this to the background to continue using your terminal.
When you are done, type fg[Enter] and then Ctrl-C.
Next time you can pass the user number on the command line if you like.
HEREDOC
$stdin.gets
end
end
end
Expand Down

0 comments on commit 170114d

Please sign in to comment.