Class: NeocitiesRed::CliDisplay
- Inherits:
-
Object
- Object
- NeocitiesRed::CliDisplay
- Defined in:
- lib/neocities_red/cli_display.rb
Constant Summary collapse
- PENELOPE_MOUTHS =
%w[^ o ~ - v U].freeze
- PENELOPE_EYES =
%w[o ~ O].freeze
Instance Method Summary collapse
- #display_api_key_saved(sitename, path) ⇒ Object
- #display_banner ⇒ Object
- #display_delete_error(resp) ⇒ Object
- #display_delete_help_and_exit ⇒ Object
- #display_delete_progress(path) ⇒ Object
- #display_delete_success ⇒ Object
- #display_diff_help_and_exit ⇒ Object
- #display_diff_results(added:, modified:, removed:) ⇒ Object
- #display_dry_run_notice ⇒ Object
- #display_gitignore_hint ⇒ Object
- #display_help_and_exit ⇒ Object
- #display_info_help_and_exit ⇒ Object
- #display_list_help_and_exit ⇒ Object
- #display_login_prompt ⇒ Object
- #display_logout_help_and_exit ⇒ Object
- #display_logout_success ⇒ Object
- #display_pizza_help_and_exit ⇒ Object
- #display_pull_help_and_exit ⇒ Object
- #display_push_help_and_exit ⇒ Object
- #display_response(resp) ⇒ Object
- #display_unknown_option(option) ⇒ Object
- #display_upload_complete ⇒ Object
- #display_upload_help_and_exit ⇒ Object
-
#initialize(io: $stdout) ⇒ CliDisplay
constructor
A new instance of CliDisplay.
- #say(message = "") ⇒ Object
Constructor Details
#initialize(io: $stdout) ⇒ CliDisplay
Returns a new instance of CliDisplay.
10 11 12 13 |
# File 'lib/neocities_red/cli_display.rb', line 10 def initialize(io: $stdout) @io = io @pastel = Pastel.new(eachline: "\n") end |
Instance Method Details
#display_api_key_saved(sitename, path) ⇒ Object
59 60 61 |
# File 'lib/neocities_red/cli_display.rb', line 59 def display_api_key_saved(sitename, path) say "The api key for #{@pastel.bold(sitename)} has been stored in #{@pastel.bold(path)}." end |
#display_banner ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/neocities_red/cli_display.rb', line 229 def say <<~HERE |\\---/| | #{PENELOPE_EYES.sample}_#{PENELOPE_EYES.sample} | #{@pastel.on_red.bold ' Neocities red '} \\_#{PENELOPE_MOUTHS.sample}_/ HERE end |
#display_delete_error(resp) ⇒ Object
83 84 85 86 |
# File 'lib/neocities_red/cli_display.rb', line 83 def display_delete_error(resp) @io.print "\n" display_response(resp) end |
#display_delete_help_and_exit ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/neocities_red/cli_display.rb', line 118 def display_delete_help_and_exit say <<~HERE #{@pastel.green.bold 'delete'} - Delete files on your Neocities site #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red delete myfile.jpg'} Delete myfile.jpg #{@pastel.green '$ neocities-red delete myfile.jpg myfile2.jpg'} Delete myfile.jpg and myfile2.jpg #{@pastel.green '$ neocities-red delete mydir'} Deletes mydir and everything inside it (be careful!) HERE exit end |
#display_delete_progress(path) ⇒ Object
75 76 77 |
# File 'lib/neocities_red/cli_display.rb', line 75 def display_delete_progress(path) @io.print @pastel.bold("Deleting #{path} ... ") end |
#display_delete_success ⇒ Object
79 80 81 |
# File 'lib/neocities_red/cli_display.rb', line 79 def display_delete_success @io.print "#{@pastel.green.bold('SUCCESS')}\n" end |
#display_diff_help_and_exit ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/neocities_red/cli_display.rb', line 184 def display_diff_help_and_exit say <<~HERE #{@pastel.green.bold 'diff'} - Compare local files with remote and show differences. #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red diff .'} Compare your current path with remote #{@pastel.green '$ neocities-red diff ./my-website'} Compare ./my-website folder with remote #{@pastel.green '$ neocities-red diff . --ignore-dotfiles'} Compare your current path with remote without files starting with '.' #{@pastel.green '$ neocities-red diff . -e file.png'} Compare your current path with remote without file.png HERE exit end |
#display_diff_results(added:, modified:, removed:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/neocities_red/cli_display.rb', line 38 def display_diff_results(added:, modified:, removed:) if removed.any? say @pastel.bold.red("Removed files") say removed end if modified.any? say @pastel.bold.yellow("Modified files") say modified end return unless added.any? say @pastel.bold.green("New files") say added end |
#display_dry_run_notice ⇒ Object
71 72 73 |
# File 'lib/neocities_red/cli_display.rb', line 71 def display_dry_run_notice say @pastel.green.bold("Doing a dry run, not actually pushing anything") end |
#display_gitignore_hint ⇒ Object
88 89 90 |
# File 'lib/neocities_red/cli_display.rb', line 88 def display_gitignore_hint say "Not pushing .gitignore entries (--no-gitignore to disable)" end |
#display_help_and_exit ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/neocities_red/cli_display.rb', line 239 def display_help_and_exit say <<~HERE #{@pastel.dim 'Subcommands:'} push Recursively upload a local directory to your site upload Upload individual files to your Neocities site delete Delete files from your Neocities site diff Compare your local directory with your Neocities site list List files from your Neocities site info Information and stats for your site logout Remove the site api key from the config version Unceremoniously display version and self destruct pull Get the most recent version of files from your site pizza Order a free pizza HERE exit end |
#display_info_help_and_exit ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/neocities_red/cli_display.rb', line 203 def display_info_help_and_exit say <<~HERE #{@pastel.green.bold 'info'} - Get site info #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red info fauux'} Gets info for 'fauux' site HERE exit end |
#display_list_help_and_exit ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/neocities_red/cli_display.rb', line 101 def display_list_help_and_exit say <<~HERE #{@pastel.green.bold 'list'} - List files on your Neocities site #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red list /'} List files in your root directory #{@pastel.green '$ neocities-red list -a'} Recursively display all files and directories #{@pastel.green '$ neocities-red list -d /mydir'} Show detailed information on /mydir HERE exit end |
#display_login_prompt ⇒ Object
55 56 57 |
# File 'lib/neocities_red/cli_display.rb', line 55 def display_login_prompt say "Please login to get your API key:" end |
#display_logout_help_and_exit ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/neocities_red/cli_display.rb', line 216 def display_logout_help_and_exit say <<~HERE #{@pastel.green.bold 'logout'} - Remove the site api key from the config #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red logout -y'} HERE exit end |
#display_logout_success ⇒ Object
67 68 69 |
# File 'lib/neocities_red/cli_display.rb', line 67 def display_logout_success say @pastel.bold("Your api key has been removed.") end |
#display_pizza_help_and_exit ⇒ Object
96 97 98 99 |
# File 'lib/neocities_red/cli_display.rb', line 96 def display_pizza_help_and_exit say Services::Pizza.new.make_order exit end |
#display_pull_help_and_exit ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/neocities_red/cli_display.rb', line 150 def display_pull_help_and_exit say <<~HERE #{@pastel.magenta.bold 'pull'} - Get the most recent version of files from your site, does not download if files haven't changed HERE exit end |
#display_push_help_and_exit ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/neocities_red/cli_display.rb', line 159 def display_push_help_and_exit say <<~HERE #{@pastel.green.bold 'push'} - Recursively upload a local directory to your Neocities site #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red push .'} Recursively upload current directory. #{@pastel.green '$ neocities-red push -e node_modules -e secret.txt .'} Exclude certain files from push #{@pastel.green '$ neocities-red push --no-gitignore .'} Don't use .gitignore to exclude files #{@pastel.green '$ neocities-red push --ignore-dotfiles .'} Ignore files with '.' at the beginning (for example, '.git/') #{@pastel.green '$ neocities-red push --dry-run .'} Just show what would be uploaded #{@pastel.green '$ neocities-red push --optimized .'} Do not upload unchanged files. #{@pastel.green '$ neocities-red push --prune .'} Delete site files not in dir (be careful!) HERE exit end |
#display_response(resp) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/neocities_red/cli_display.rb', line 19 def display_response(resp) if resp.is_a?(Exception) say "#{@pastel.red.bold('ERROR:')} #{resp.}" exit end if resp[:result] == "success" say "#{@pastel.green.bold('SUCCESS:')} #{resp[:message]}" elsif resp[:result] == "error" && resp[:error_type] == "file_exists" out = "#{@pastel.yellow.bold('EXISTS:')} #{resp[:message]}" out += " (#{resp[:error_type]})" if resp[:error_type] say out else out = "#{@pastel.red.bold('ERROR:')} #{resp[:message]}" out += " (#{resp[:error_type]})" if resp[:error_type] say out end end |
#display_unknown_option(option) ⇒ Object
63 64 65 |
# File 'lib/neocities_red/cli_display.rb', line 63 def display_unknown_option(option) say @pastel.red.bold("Unknown option: #{option.inspect}") end |
#display_upload_complete ⇒ Object
92 93 94 |
# File 'lib/neocities_red/cli_display.rb', line 92 def display_upload_complete say "All files uploaded." end |
#display_upload_help_and_exit ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/neocities_red/cli_display.rb', line 135 def display_upload_help_and_exit say <<~HERE #{@pastel.green.bold 'upload'} - Upload file to your Neocities site to the specific path #{@pastel.dim 'Examples:'} #{@pastel.green '$ neocities-red upload ./img.jpg ./images/img2.jpg'} Upload img.jpg to /images folder and with img2.jpg name #{@pastel.green '$ neocities-red upload images/ images/'} Upload images folder with their content to /images folder HERE exit end |
#say(message = "") ⇒ Object
15 16 17 |
# File 'lib/neocities_red/cli_display.rb', line 15 def say( = "") @io.puts() end |