Class: Multisync::Cli
- Inherits:
-
Object
- Object
- Multisync::Cli
- Defined in:
- lib/multisync/cli.rb
Instance Attribute Summary collapse
-
#sets ⇒ Object
readonly
Given sets to run or empty.
Class Method Summary collapse
Instance Method Summary collapse
- #catalog ⇒ Object
- #options ⇒ Object
- #parser ⇒ Object
- #runtime ⇒ Object
- #start ⇒ Object
- #tasks ⇒ Object
Instance Attribute Details
#sets ⇒ Object (readonly)
Given sets to run or empty
13 14 15 |
# File 'lib/multisync/cli.rb', line 13 def sets @sets end |
Class Method Details
.start ⇒ Object
8 9 10 |
# File 'lib/multisync/cli.rb', line 8 def self.start new.start end |
Instance Method Details
#catalog ⇒ Object
82 83 84 |
# File 'lib/multisync/cli.rb', line 82 def catalog @_catalog ||= Multisync::Catalog.new [:file] end |
#options ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/multisync/cli.rb', line 90 def @_options ||= { list: false, print: false, dryrun: false, quiet: false, file: Multisync::Catalog.default_catalog_path, timeout: 31536000, # 1 year } end |
#parser ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/multisync/cli.rb', line 15 def parser OptionParser.new do |o| o. = "\nRun rsync jobs defined in the catalog file '#{[:file]}'.\n\n" + "Usage: #{File.basename $0} [options] [SET] [...]\n\n" + " SET selects a section from the catalog (see option -l)\n" + " use / as a group/task separator.\n" + " e.g. #{File.basename $0} nas/userdata" o.separator '' o.on('-l', '--list', "List the catalog") do [:list] = true end o.on('-p', '--print', "Print the commands without executing them") do [:print] = true end o.on('-q', '--quiet', "Show only rsync summary") do [:quiet] = true end o.on('--catalog FILE', "Specify a catalog", "Default is #{[:file]}") do |file| [:file] = file end o.on('--timeout SECS', Integer, "Timeout for rsync job", "Default is #{[:timeout]}") do |timeout| [:timeout] = timeout end o.on('-n', '--dryrun', "Run rsync in dry-run mode") do [:dryrun] = true end o.separator '' end end |
#runtime ⇒ Object
86 87 88 |
# File 'lib/multisync/cli.rb', line 86 def runtime @_runtime ||= Multisync::Runtime.new() end |
#start ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/multisync/cli.rb', line 45 def start parser.parse! [:quiet] = false if [:print] @sets = ARGV if [:list] # List tasks puts "Catalog: #{[:file].color(:cyan)}" puts puts Multisync::List.new catalog else # Run tasks return if tasks.empty? begin tasks.each do |task| runtime.run task end rescue Interrupt => e $stderr.puts "\nAborted!".color(:red) end unless [:print] puts puts puts Multisync::Summary.new tasks end end puts end |