Class: SKP::CLI
- Inherits:
-
Thor
- Object
- Thor
- SKP::CLI
- Defined in:
- lib/skp/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #complete ⇒ Object
- #current ⇒ Object
- #download ⇒ Object
- #list ⇒ Object
- #next ⇒ Object
- #reset ⇒ Object
- #set_progress ⇒ Object
- #show ⇒ Object
- #start ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
18 19 20 |
# File 'lib/skp/cli.rb', line 18 def self.exit_on_failure? true end |
Instance Method Details
#complete ⇒ Object
98 99 100 101 |
# File 'lib/skp/cli.rb', line 98 def complete say "Marked current lesson as complete" client.complete(nil) end |
#current ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/skp/cli.rb', line 89 def current exit_with_no_key content = client.current say "Opening: #{content["title"]}" client.download_and_extract(content) display_content(content, ![:"no-open"]) end |
#download ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/skp/cli.rb', line 148 def download exit_with_no_key total = client.list.size client.list.each do |content| current = client.list.index(content) + 1 puts "Downloading #{content["title"]} (#{current}/#{total})" client.download_and_extract(content) end end |
#list ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/skp/cli.rb', line 104 def list ::CLI::UI::Frame.open("{{*}} {{bold:All Lessons}}", color: :green) frame_open = false client.list.each do |lesson| if lesson["title"].start_with?("Sidekiq in Practice") ::CLI::UI::Frame.close(nil) if frame_open ::CLI::UI::Frame.open(lesson["title"]) frame_open = true next end no_data = client.send(:client_data)["completed"].nil? completed = client.send(:client_data)["completed"]&.include?(lesson["position"]) str = if no_data "" elsif completed "\u{2705} " else "\u{274C} " end indent = lesson["indent"].to_i || 0 indent = " " * indent case lesson["style"] when "video" puts str + ::CLI::UI.fmt("#{indent}{{red:#{lesson["title"]}}}") when "quiz" # puts ::CLI::UI.fmt "{{green:#{" " + lesson["title"]}}}" when "lab" puts str + ::CLI::UI.fmt("#{indent}{{yellow:#{lesson["title"]}}}") when "text" puts str + ::CLI::UI.fmt("#{indent}{{magenta:#{lesson["title"]}}}") else puts str + ::CLI::UI.fmt("#{indent}{{magenta:#{lesson["title"]}}}") end end ::CLI::UI::Frame.close(nil) ::CLI::UI::Frame.close(nil, color: :green) end |
#next ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/skp/cli.rb', line 70 def next exit_with_no_key content = client.next if content.nil? SKP::CLI.new. say "Congratulations!" say "You have completed Sidekiq in Practice." exit(0) end say "Proceeding to next lesson: #{content["title"]}" client.download_and_extract(content) client.complete(content["position"]) display_content(content, ![:"no-open"]) end |
#reset ⇒ Object
187 188 189 190 191 |
# File 'lib/skp/cli.rb', line 187 def reset return unless ::CLI::UI.confirm("Are you sure you want to erase all of your progress?", default: false) say "Resetting progress." client.set_progress(nil) end |
#set_progress ⇒ Object
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/skp/cli.rb', line 175 def set_progress title = ::CLI::UI::Prompt.ask( "Which lesson would you like to set your progress to? All prior lessons will be marked complete", options: client.list.reject { |l| l["title"] == "Quiz" }.map { |l| " " * l["indent"] + l["title"] } ) title.strip! content_order = client.list.find { |l| l["title"] == title }["position"] content = client.set_progress(content_order, all_prior: true) say "Setting current progress to #{content.last["title"]}" end |
#show ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/skp/cli.rb', line 161 def show exit_with_no_key title = ::CLI::UI::Prompt.ask( "Which lesson would you like to view?", options: client.list.reject { |l| ![:quizzes] && l["title"] == "Quiz" }.map { |l| " " * l["indent"] + l["title"] } ) title.strip! content_order = client.list.find { |l| l["title"] == title }["position"] content = client.show(content_order) client.download_and_extract(content) display_content(content, ![:"no-open"]) end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/skp/cli.rb', line 23 def start warn_if_already_started say "\u{1F48E} Welcome to Sidekiq in Practice. \u{1F48E}" say "" say "This is skp, the command line client for this workshop." say "" say "This client will download files from the internet into the current" say "working directory, so it's best to run this client from a new directory" say "that you'll use as your 'scratch space' for working on the Workshop." say "" ans = ::CLI::UI.confirm "Create files and folders in this directory? (no will quit)" exit(1) unless ans say "" ans = ::CLI::UI::Prompt.ask("Where should we save your course progress?", options: [ "here", "my home directory (~/.skp)" ]) client.directory_setup((ans == "my home directory (~/.skp)")) key = ::CLI::UI::Prompt.ask("Your Purchase Key: ").strip unless client.setup(key) say "That is not a valid key. Please try again." exit(0) end say "" say "Successfully authenticated with the SKP server and saved your key." say "" say "Setup complete!" say "" say "To learn how to use this command-line client, consult ./README.md," say "which we just created." say "" say "Once you've read that and you're ready to get going: $ skp next" end |