Class: Toy::Core::CLI::Fetch
- Inherits:
-
Object
- Object
- Toy::Core::CLI::Fetch
- Defined in:
- lib/toy/core/cli/fetch.rb
Constant Summary collapse
- FORMAT =
"toy/fetch-v1"
Instance Method Summary collapse
-
#initialize(argv) ⇒ Fetch
constructor
A new instance of Fetch.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Fetch
Returns a new instance of Fetch.
31 32 33 34 35 36 |
# File 'lib/toy/core/cli/fetch.rb', line 31 def initialize(argv) @argv = argv @json = false @repo = nil @file = nil end |
Instance Method Details
#run ⇒ Object
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 67 68 |
# File 'lib/toy/core/cli/fetch.rb', line 38 def run parsed = parse_args return parsed unless parsed == true unless @file # No file: print the common-pick hints (folded from # fetch_model.sh:34-40) and return bad-input. The bash script's # `exit 1` predates the exit-code contract; 2 (missing required # arg) is the consistent choice here. return missing_file end cache_path = download return cache_path if cache_path.is_a?(Integer) # error code link = link_into_data(cache_path) return link if link.is_a?(Integer) if @json puts JSON.pretty_generate( "format" => FORMAT, "repo" => @repo, "file" => @file, "cache_path" => cache_path, "link" => link ) else puts "linked #{link} -> #{cache_path}" end EXIT_OK end |