Class: NewlineHw::Cli
- Inherits:
-
Thor
- Object
- Thor
- NewlineHw::Cli
- Defined in:
- lib/newline_hw/cli.rb
Instance Method Summary collapse
- #config ⇒ Object
- #gui_trigger(id) ⇒ Object
- #init ⇒ Object
- #install ⇒ Object
- #install_chrome_hook ⇒ Object
- #run_command(working_dir, _submission_id = nil) ⇒ Object
- #setup_command(submission_id) ⇒ Object
- #uninstall ⇒ Object
- #upgrade ⇒ Object
Instance Method Details
#config ⇒ Object
10 11 12 |
# File 'lib/newline_hw/cli.rb', line 10 def config `#{NewlineHw.config.editor} #{NewlineHw::Config::CONFIG_PATH}` end |
#gui_trigger(id) ⇒ Object
92 93 94 |
# File 'lib/newline_hw/cli.rb', line 92 def gui_trigger(id) GuiTrigger.new({ id: id }, config).call end |
#install ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/newline_hw/cli.rb', line 16 def install NewlineHw::Config.install_default say "Installed a config file to `#{NewlineHw::Config::CONFIG_PATH}`" install_chrome_hook say "" say ("*" * 30) + " YOU MUST!! Add this line to your shell profile " + ("*" * 30), :red say '$ eval "$(newline_hw init)"' say ("*" * 30), :red end |
#install_chrome_hook ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/newline_hw/cli.rb', line 34 def install_chrome_hook NewlineHw.make_log_directory begin ChromeManifest.write say "Chrome Native Messaging Hook installed for Newline Assistant", :green rescue Errno::EACCES => e path = "~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.theironyard.newlinecli.hw.json" say "Could NOT add chrome native messaging hook please check permissions for #{path} and that containing folder exists with 0600 permissions.", :red say "*" * 80 say "" say " sudo chown -R $(whoami) #{path} " say "" say "Error Message: #{e.}" end end |
#run_command(working_dir, _submission_id = nil) ⇒ Object
85 86 87 |
# File 'lib/newline_hw/cli.rb', line 85 def run_command(working_dir, _submission_id = nil) puts Shell::Run.new(working_dir, config).cmd end |
#setup_command(submission_id) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/newline_hw/cli.rb', line 67 def setup_command(submission_id) puts Shell::Setup.new(submission_id, config).cmd rescue NewlineHw::AuthenticationError => e say "Could not log into Newline using NewlineCLI, have you logged in?" say "Error from NewlineCli #{e.}" exit 3 rescue Excon::Error::Socket => e say "Error could not open a connection to newline. Do you have internet?" say "Error message #{e.}" exit 3 rescue Excon::Error::Forbidden => e say "You do not have access to this submission." say "Error message #{e.}" exit 3 end |
#uninstall ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/newline_hw/cli.rb', line 52 def uninstall NewlineHw.remove_log_directory say "Chrome Messaging Logs REMOVED", :green ChromeManifest.remove say "Chrome Native Messaging Hook REMOVED", :green say "Finish uninstall with these commands" say "" say " rm #{NewlineHw::Config::CONFIG_PATH}" say " gem uninstall newline_hw --executables" say "" end |
#upgrade ⇒ Object
27 28 29 |
# File 'lib/newline_hw/cli.rb', line 27 def upgrade `gem install newline_hw && newline_hw install_chrome_hook` end |