Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ devices:

Wavesync will exit with an error if a device model in the config is not supported.

## Help

```bash
wavesync help
```

## Usage

```bash
Expand Down
60 changes: 59 additions & 1 deletion lib/wavesync/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'optparse'
require 'rainbow'

module Wavesync
class CLI
Expand All @@ -14,9 +15,11 @@ def self.start
start_analyze
when 'set'
start_set
when 'help'
start_help
else
puts "Unknown command: #{command}"
puts 'Available commands: sync, analyze, set'
puts 'Available commands: sync, analyze, set, help'
exit 1
end
end
Expand Down Expand Up @@ -138,6 +141,61 @@ def self.require_set_name(subcommand)
name
end

def self.start_help
subcommand = ARGV.shift

case subcommand
when 'sync'
OptionParser.new do |opts|
opts.banner = 'Usage: wavesync sync [options]'
opts.on('-d', '--device NAME', 'Name of device to sync (as defined in config)')
opts.on('-c', '--config PATH', 'Path to wavesync config YAML file')
opts.on('-p', '--pad', 'Pad tracks with silence so total length is a multiple of 64 bars (Octatrack only)')
puts opts
end
when 'analyze'
OptionParser.new do |opts|
opts.banner = 'Usage: wavesync analyze [options]'
opts.on('-c', '--config PATH', 'Path to wavesync config YAML file')
opts.on('-f', '--force', 'Overwrite existing BPM values')
puts opts
end
when 'set'
puts 'Usage: wavesync set <subcommand> [options]'
puts ''
puts 'Subcommands:'
puts ' create NAME Create a new track set'
puts ' edit NAME Edit an existing track set'
puts ' list List all track sets'
puts ''
puts 'Options:'
puts ' -c, --config PATH Path to wavesync config YAML file'
when nil
puts 'Usage: wavesync [command] [options]'
puts ''
puts 'Commands:'
puts ' sync Sync music library to a device'
puts Rainbow(' -d, --device NAME Name of device to sync (as defined in config)').darkgray
puts Rainbow(' -p, --pad Pad tracks with silence so total length is a multiple of 64 bars (Octatrack only)').darkgray
puts ''
puts ' analyze Detect and write BPM metadata to library tracks'
puts Rainbow(' -f, --force Overwrite existing BPM values').darkgray
puts ''
puts ' set create NAME Create a new track set'
puts ' set edit NAME Edit an existing track set'
puts ' set list List all track sets'
puts ''
puts ' help Show this help message'
puts ''
puts 'Options:'
puts Rainbow(' -c, --config PATH Path to wavesync config YAML file').darkgray
else
puts "Unknown command: #{subcommand}"
puts 'Available commands: sync, analyze, set'
exit 1
end
end

def self.start_analyze
options = {}
parser = OptionParser.new do |opts|
Expand Down
23 changes: 23 additions & 0 deletions test/wavesync/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,28 @@ def teardown

assert_raises(SystemExit) { CLI.start_sync }
end

test 'prints help when help command is given' do
ARGV.replace(['help'])

output = capture_io { CLI.start }.first

assert_includes output, 'sync'
assert_includes output, 'analyze'
assert_includes output, 'set'
assert_includes output, 'help'
end

test 'help output includes usage line' do
output = capture_io { CLI.start_help }.first

assert_includes output, 'Usage: wavesync'
end

test 'help output includes options section' do
output = capture_io { CLI.start_help }.first

assert_includes output, 'Options:'
end
end
end
Loading