Class: NeocitiesRed::CLI
- Inherits:
-
Thor
- Object
- Thor
- NeocitiesRed::CLI
- Defined in:
- lib/neocities_red/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(*paths) ⇒ Object
- #diff(path = ".") ⇒ Object
- #help(command = nil) ⇒ Object
- #info(sitename = nil) ⇒ Object
- #list(path = nil) ⇒ Object
- #logout ⇒ Object
- #pizza ⇒ Object
- #pull ⇒ Object
- #purge ⇒ Object
- #push(root = nil) ⇒ Object
- #upload(local_path = nil, remote_path = nil) ⇒ Object
- #version ⇒ Object
Class Method Details
.app_config_path(name) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/neocities_red/cli.rb', line 175 def self.app_config_path(name) platform = case RUBY_PLATFORM when /cygwin|mswin|mingw|bccwin|wince|emx|win32/ :windows when /darwin/ :darwin when /linux/ :linux when /freebsd/ :freebsd else :unknown end case platform when :linux return File.join(ENV["XDG_CONFIG_HOME"], name) if ENV["XDG_CONFIG_HOME"] return File.join(Dir.home, ".config", name) if Dir.home when :darwin return File.join(Dir.home, "Library", "Application Support", name) if Dir.home when :windows return File.join(ENV["LOCALAPPDATA"], name) if ENV["LOCALAPPDATA"] if ENV["USERPROFILE"] return File.join( ENV["USERPROFILE"], "AppData", "Local", name ) end else # FreeBSD and other unknown UNIX-like systems use dotfile directly in home directory return File.join(Dir.home, ".#{name}") if Dir.home end nil end |
Instance Method Details
#delete(*paths) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/neocities_red/cli.rb', line 45 def delete(*paths) return display_help_for("delete") if paths.empty? || help_requested?([:help], paths) client = ensure_client! paths.each { |path| Services::File::Remover.new(client, path).remove } end |
#diff(path = ".") ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/neocities_red/cli.rb', line 26 def diff(path = ".") return display_help_for("diff") if help_requested?([:help], path) client = ensure_client! exclude = build_diff_exclusions(path, Array([:exclude])) added, modified, removed = Services::Site::Differencer.new( client, path: path, detail: false, ignore_dotfiles: [:ignore_dotfiles], exclude: exclude ).show display.display_diff_results(added: added, modified: modified, removed: removed) end |
#help(command = nil) ⇒ Object
215 216 217 218 219 220 221 222 |
# File 'lib/neocities_red/cli.rb', line 215 def help(command = nil) return display.display_help_and_exit if command.nil? custom_help_method = "display_#{command}_help_and_exit" return display.public_send(custom_help_method) if display.respond_to?(custom_help_method) super end |
#info(sitename = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/neocities_red/cli.rb', line 64 def info(sitename = nil) return display_help_for("info") if help_requested?([:help], sitename) client = ensure_client! profile_info = Services::Site::Informer.new(client, [sitename].compact, @sitename).pretty_print display.say TTY::Table.new(profile_info) rescue StandardError => e display.display_response(e) end |
#list(path = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/neocities_red/cli.rb', line 78 def list(path = nil) if help_requested?([:help], path) || (path.nil? && [:all].nil? && [:detail].nil?) display_help_for("list") return end client = ensure_client! path = nil if [:all] display.say Services::File::List.new(client, path, [:detail]).show end |
#logout ⇒ Object
55 56 57 58 59 60 |
# File 'lib/neocities_red/cli.rb', line 55 def logout return display_help_for("logout") if help_requested?([:help]) || ![:yes] FileUtils.rm_f(app_config_path) display.display_logout_success end |
#pizza ⇒ Object
171 172 173 |
# File 'lib/neocities_red/cli.rb', line 171 def pizza display_help_for(__method__) end |
#pull ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/neocities_red/cli.rb', line 138 def pull return display_help_for("pull") if help_requested?([:help]) client = ensure_client! data = read_config || {} last_pull_time = data.dig("LAST_PULL", "time") last_pull_loc = data.dig("LAST_PULL", "loc") Services::Site::Exporter.new(client, @sitename, data, app_config_path) .export(quiet: [:quiet], last_pull_time: last_pull_time, last_pull_loc: last_pull_loc) end |
#purge ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/neocities_red/cli.rb', line 153 def purge return display_help_for("purge") unless [:yes] client = ensure_client! resp = client.list resp[:files].each do |file| display.display_delete_progress(file[:path]) delete_resp = client.delete_wrapper_with_dry_run(file[:path], dry_run: [:dry_run]) if delete_resp[:result] == "success" display.display_delete_success else display.display_delete_error(delete_resp) end end end |
#push(root = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/neocities_red/cli.rb', line 97 def push(root = nil) return display_help_for("push") if help_requested?([:help], root) client = ensure_client! return display_help_for("push") if root.nil? Services::Site::Pusher.new( client, display, root: root, no_gitignore: [:no_gitignore], ignore_dotfiles: [:ignore_dotfiles], exclude: Array([:exclude]), dry_run: [:dry_run], prune: [:prune], optimized: [:optimized] ).push rescue ArgumentError => e display.display_response(result: "error", message: e.) display_help_for("push") end |
#upload(local_path = nil, remote_path = nil) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/neocities_red/cli.rb', line 121 def upload(local_path = nil, remote_path = nil) return display_help_for("upload") if help_requested?([:help], [local_path, remote_path]) return display_help_for("upload") if local_path.nil? || remote_path.nil? client = ensure_client! if File.file?(local_path) Services::File::Uploader.new(client, local_path, remote_path).upload elsif File.directory?(local_path) folder_uploader = Services::File::FolderUploader.new(client, local_path, remote_path) files_list = folder_uploader.files folder_uploader.upload(files_list) end end |
#version ⇒ Object
225 226 227 |
# File 'lib/neocities_red/cli.rb', line 225 def version display.say NeocitiesRed::VERSION end |