Class: BooticCli::CLI
- Inherits:
-
Thor
- Object
- Thor
- BooticCli::CLI
- Includes:
- Connectivity, Thor::Actions
- Defined in:
- lib/bootic_cli/cli.rb
Constant Summary collapse
- CUSTOM_COMMANDS_DIR =
ENV.fetch("BTC_CUSTOM_COMMANDS_PATH") { File.join(ENV["HOME"], "btc") }
Class Method Summary collapse
Instance Method Summary collapse
- #console ⇒ Object
- #erase ⇒ Object
- #info ⇒ Object
- #login(scope = 'admin') ⇒ Object
- #logout ⇒ Object
- #runner(filename) ⇒ Object
- #setup ⇒ Object
Class Method Details
.sub(klass, descr) ⇒ Object
106 107 108 109 |
# File 'lib/bootic_cli/cli.rb', line 106 def self.sub(klass, descr) command_name = underscore(klass.name) register klass, command_name, "#{command_name} SUBCOMMAND ...ARGS", descr end |
Instance Method Details
#console ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/bootic_cli/cli.rb', line 81 def console logged_in_action do require 'irb' require 'irb/completion' IRB.setup nil IRB.conf[:MAIN_CONTEXT] = IRB::Irb.new.context require 'irb/ext/multi-irb' require 'bootic_cli/console' context = Console.new(root) prompt = "/#{shop.subdomain} (#{root.user_name}|#{root.scopes}) $ " IRB.conf[:PROMPT][:CUSTOM] = { :PROMPT_I => prompt, :PROMPT_S => "%l>> ", :PROMPT_C => prompt, :PROMPT_N => prompt, :RETURN => "=> %s\n" } IRB.conf[:PROMPT_MODE] = :CUSTOM IRB.conf[:AUTO_INDENT] = false IRB.irb nil, context end end |
#erase ⇒ Object
51 52 53 54 |
# File 'lib/bootic_cli/cli.rb', line 51 def erase session.erase! say "all credentials erased from this computer" end |
#info ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bootic_cli/cli.rb', line 57 def info logged_in_action do print_table([ ['username', root.user_name], ['email', root.email], ['scopes', root.scopes], ['shop', "#{shop.url} (#{shop.subdomain})"], ['custom commands dir', CUSTOM_COMMANDS_DIR] ]) say_status 'OK', 'API connection is working', :green end end |
#login(scope = 'admin') ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bootic_cli/cli.rb', line 23 def login(scope = 'admin') if !session.setup? say "App not configured. Running setup first. You only need to do this once." say "Please create an OAuth2 app and get its credentials at https://auth.bootic.net/dev/apps" invoke :setup, [] end username = ask("Enter your Bootic email") pwd = ask("Enter your Bootic password:", echo: false) say "Loging in as #{username}. Getting access token..." begin session.login username, pwd, scope say "Logged in as #{username} (#{scope})" say "try: btc help" rescue StandardError => e say e. end end |
#logout ⇒ Object
45 46 47 48 |
# File 'lib/bootic_cli/cli.rb', line 45 def logout session.logout! say_status 'Logged out', 'You are now logged out', :red end |
#runner(filename) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/bootic_cli/cli.rb', line 72 def runner(filename) require 'bootic_cli/file_runner' logged_in_action do FileRunner.run(root, filename) end end |
#setup ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/bootic_cli/cli.rb', line 13 def setup client_id = ask("Enter your application's client_id:") client_secret = ask("Enter your application's client_secret:") session.setup(client_id, client_secret) say "Credentials stored. client_id: #{client_id}" end |