Class: Manifestly::CLI
- Inherits:
-
Thor
- Object
- Thor
- Manifestly::CLI
- Includes:
- CommandLineReporter, Ui
- Defined in:
- lib/manifestly/cli.rb
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
- .file_option(description_action = nil) ⇒ Object
- .repo_file_option(description = nil) ⇒ Object
- .repo_option ⇒ Object
-
.search_paths_option ⇒ Object
Common command line options.
Instance Method Summary collapse
- #apply ⇒ Object
- #create ⇒ Object
- #diff ⇒ Object
- #download ⇒ Object
- #find ⇒ Object
- #list ⇒ Object
- #tag ⇒ Object
- #upload ⇒ Object
- #version ⇒ Object
Methods included from Ui
Class Method Details
.exit_on_failure? ⇒ Boolean
17 18 19 |
# File 'lib/manifestly/cli.rb', line 17 def self.exit_on_failure? true end |
.file_option(description_action = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/manifestly/cli.rb', line 51 def self.file_option(description_action=nil) description = "The local manifest file" description += " to #{description_action}" if description_action method_option :file, desc: description, type: :string, banner: '', required: true end |
.repo_file_option(description = nil) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/manifestly/cli.rb', line 42 def self.repo_file_option(description=nil) description ||= "The name of the repository file, with path if applicable" method_option :repo_file, desc: description, type: :string, banner: '', required: true end |
.repo_option ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/manifestly/cli.rb', line 34 def self.repo_option method_option :repo, desc: "The github manifest repository to use, given as 'organization/reponame'", type: :string, banner: '', required: true end |
.search_paths_option ⇒ Object
Common command line options
25 26 27 28 29 30 31 32 |
# File 'lib/manifestly/cli.rb', line 25 def self.search_paths_option method_option :search_paths, desc: "A list of paths where git repositories can be found", type: :array, required: false, banner: '', default: '.' end |
Instance Method Details
#apply ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/manifestly/cli.rb', line 224 def apply begin manifest = load_manifest(file: [:file]) || error! manifest.items.each{ |item| item.checkout_commit!([:update]) } rescue Manifestly::ManifestItem::MultipleSameNameRepositories => e say "Multiple repositories have the same name (#{e.}) so we " + "can't apply the manifest. Try limiting the search_paths or " + "separate the duplicates." error! rescue Manifestly::Repository::CommitNotPresent => e say "Could not find commit #{e.sha} in repository #{e.repository.github_name_or_path}. " + "Try running again with the `--update` option." error! end end |
#create ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/manifestly/cli.rb', line 187 def create manifest = if [:based_on] load_manifest(file: [:based_on]) || error! else Manifest.new end if [:interactive] (manifest) else repos_to_remove = ([:remove]) repos_to_remove.each do |repo_to_remove| manifest.remove_repository(repo_to_remove) end repos_to_add = ([:add]) repos_to_add.each do |repo_to_add| manifest.add_repository(repo_to_add) end write_manifest(manifest, false) end end |
#diff ⇒ Object
449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/manifestly/cli.rb', line 449 def diff repository = Repository.load_cached([:repo], update: true) from_manifest = load_manifest(repository: repository, sha: [:from_sha]) to_manifest = load_manifest(repository: repository, sha: [:to_sha]) if !from_manifest || !to_manifest say("Could not load the 'from' manifest so cannot continue with the diff.") if !from_manifest say("Could not load the 'to' manifest so cannot continue with the diff.") if !to_manifest error! end manifest_diff = ManifestDiff.new(from_manifest, to_manifest) manifest_diff.to_markdown end |
#download ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/manifestly/cli.rb', line 284 def download repository = Repository.load_cached([:repo], update: true) commit_content = begin repository.get_commit_content([:sha]) rescue Manifestly::Repository::CommitNotPresent say('That SHA is invalid') error! end save_as = [:save_as] if save_as.nil? # Get the whole SHA so filenames are consistent sha = repository.find_commit([:sha]).sha save_as = "#{sha[0..9]}.manifest" end File.open(save_as, 'w') { |file| file.write(commit_content) } say "Downloaded #{save_as}. #{commit_content.split("\n").count} line(s)." end |
#find ⇒ Object
415 416 417 418 419 420 |
# File 'lib/manifestly/cli.rb', line 415 def find repository = Repository.load_cached([:repo], update: true) shas = repository.get_shas_with_tag(tag: [:tag], file: [:repo_file]) shas = shas.take([:limit].to_i) if [:limit] say shas.uniq.join("\n") end |
#list ⇒ Object
315 316 317 318 319 |
# File 'lib/manifestly/cli.rb', line 315 def list repository = Repository.load_cached([:repo], update: true) commits = repository.file_commits([:repo_file]) (commits, show_author: true) end |
#tag ⇒ Object
365 366 367 368 369 370 371 372 373 374 |
# File 'lib/manifestly/cli.rb', line 365 def tag repository = Repository.load_cached([:repo], update: true) begin repository.tag_scoped_to_file( tag: [:tag], sha: [:sha], message: [:message], push: true ) rescue Manifestly::Repository::ShaAlreadyTagged end end |
#upload ⇒ Object
256 257 258 259 260 261 262 263 264 265 |
# File 'lib/manifestly/cli.rb', line 256 def upload repository = Repository.load_cached([:repo], update: true) begin repository.push_file!([:file], [:repo_file], [:message]) rescue Manifestly::Repository::ManifestUnchanged ensure say repository.current_commit end end |
#version ⇒ Object
465 466 467 |
# File 'lib/manifestly/cli.rb', line 465 def version say "Manifestly #{Manifestly::VERSION} - https://github.com/openstax/manifestly" end |