Class: Wavesync::CLI
- Inherits:
-
Object
- Object
- Wavesync::CLI
- Defined in:
- lib/wavesync/cli.rb
Class Method Summary collapse
- .load_config(path) ⇒ Object
- .require_set_name(subcommand) ⇒ Object
- .start ⇒ Object
- .start_analyze ⇒ Object
- .start_set ⇒ Object
- .start_sync ⇒ Object
Class Method Details
.load_config(path) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/wavesync/cli.rb', line 121 def self.load_config(path) Wavesync::Config.load(path) rescue Wavesync::ConfigError => e puts "Configuration error: #{e.}" exit 1 end |
.require_set_name(subcommand) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/wavesync/cli.rb', line 128 def self.require_set_name(subcommand) name = ARGV.shift unless name puts "Usage: wavesync set #{subcommand} <name>" exit 1 end name end |
.start ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/wavesync/cli.rb', line 7 def self.start command = ARGV.first && !ARGV.first.start_with?('-') ? ARGV.shift : 'sync' case command when 'sync' start_sync when 'analyze' start_analyze when 'set' start_set else puts "Unknown command: #{command}" puts 'Available commands: sync, analyze, set' exit 1 end end |
.start_analyze ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/wavesync/cli.rb', line 137 def self.start_analyze = {} parser = OptionParser.new do |opts| opts. = 'Usage: wavesync analyze [options]' opts.on('-c', '--config PATH', 'Path to wavesync config YAML file') do |value| [:config] = value end opts.on('-f', '--force', 'Overwrite existing BPM values') do [:overwrite] = true end end parser.parse! config_path = [:config] || Wavesync::Config::DEFAULT_PATH config = load_config(config_path) Wavesync::Analyzer.new(config.library).analyze(overwrite: [:overwrite] || false) end |
.start_set ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/wavesync/cli.rb', line 73 def self.start_set subcommand = ARGV.shift = {} parser = OptionParser.new do |opts| opts. = 'Usage: wavesync set <subcommand> [options]' opts.on('-c', '--config PATH', 'Path to wavesync config YAML file') do |value| [:config] = value end end parser.parse! config_path = [:config] || Wavesync::Config::DEFAULT_PATH config = load_config(config_path) case subcommand when 'create' name = require_set_name('create') if Wavesync::Set.exists?(config.library, name) puts "Set '#{name}' already exists. Use 'wavesync set edit #{name}' to edit it." exit 1 end set = Wavesync::Set.new(config.library, name) Wavesync::SetEditor.new(set, config.library).run when 'edit' name = require_set_name('edit') unless Wavesync::Set.exists?(config.library, name) puts "Set '#{name}' not found. Use 'wavesync set create #{name}' to create it." exit 1 end set = Wavesync::Set.load(config.library, name) Wavesync::SetEditor.new(set, config.library).run when 'list' sets = Wavesync::Set.all(config.library) if sets.empty? puts 'No sets found.' else sets.each { |s| puts "#{s.name} (#{s.tracks.size} tracks)" } end else puts "Unknown subcommand: #{subcommand || '(none)'}" puts 'Available subcommands: create, edit, list' exit 1 end end |
.start_sync ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 69 70 71 |
# File 'lib/wavesync/cli.rb', line 24 def self.start_sync = {} parser = OptionParser.new do |opts| opts. = 'Usage: wavesync sync [options]' opts.on('-d', '--device NAME', 'Name of device to sync (as defined in config)') do |value| [:device] = value end opts.on('-c', '--config PATH', 'Path to wavesync config YAML file') do |value| [:config] = value end opts.on('-p', '--pad', 'Pad tracks with silence so total length is a multiple of 64 bars (Octatrack only)') do [:pad] = true end end parser.parse! config_path = [:config] || Wavesync::Config::DEFAULT_PATH config = load_config(config_path) device_configs = config.device_configs if [:device] device_configs = device_configs.select { |device_config| device_config[:name] == [:device] } if device_configs.empty? known = config.device_configs.map { |device_config| device_config[:name] }.join(', ') puts "Unknown device \"#{[:device]}\". Devices in config: #{known}" exit 1 end end device_configs.each do |device_config| next if Wavesync::Device.find_by(name: device_config[:model]) supported = Wavesync::Device.all.map(&:name).join(', ') puts "Unknown device model \"#{device_config[:model]}\" in config. Supported models: #{supported}" exit 1 end scanner = Wavesync::Scanner.new(config.library) device_configs.each do |device_config| scanner.sync(device_config[:path], Wavesync::Device.find_by(name: device_config[:model]), pad: [:pad] || false) end end |