Class: Lydown::CLI::Commands

Inherits:
Thor
  • Object
show all
Defined in:
lib/lydown/cli/commands.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



119
120
121
122
# File 'lib/lydown/cli/commands.rb', line 119

def method_missing(method, *args)
  args = ["compile", method.to_s] + args
  self.class.start(args)
end

Instance Method Details

#compile(*args) ⇒ Object



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
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lydown/cli/commands.rb', line 46

def compile(*args)
  path = args.first || '.'

  # check if user specified a command as an argument (e.g. --version)
  if (path =~ /^\-\-(\w+)/) && respond_to?($1)
    return send($1)
  end
  
  require 'lydown'
  
  opts = Lydown::CLI::Support.copy_options(options)
  opts[:path] = path
  
  # Set format based on direct flag
  opts[:format] = opts[:format].to_sym if opts[:format]
  [:pdf, :png, :ly, :midi, :mp3].each {|f| opts[:format] = f if opts[f]}

  opts[:parts] = opts[:parts].split(',') if opts[:parts]
  opts[:movements] = opts[:movements].split(',') if opts[:movements]
  
  # Detect work directory
  Lydown::CLI::Support.detect_work_directory(opts)
  Lydown::CLI::Support.detect_filename(opts)
  
  if (opts[:format] == :midi) || (opts[:format] == :mp3)
    opts[:score_only] = true
    opts[:parts_only] = false
  end

  # compile score
  unless opts[:parts_only] || opts[:parts]
    $stderr.puts "Processing score..."
    Lydown::CLI::Compiler.process(opts.merge(mode: :score, parts: nil))
  end

  # compile parts
  unless opts[:score_only]
    $stderr.puts "Processing parts..."
    Lydown::CLI::Compiler.process(opts.merge(mode: :part))
  end
end

#proof(*args) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/lydown/cli/commands.rb', line 93

def proof(*args)
  require 'lydown'

  opts = Lydown::CLI::Support.copy_options(options)
  opts[:path] = args.first || '.'

  opts[:proof_mode] = true
  opts[:include_parts] = opts[:include_parts] && opts[:include_parts].split(',')
  opts[:open_target] = true

  Lydown::CLI::Support.detect_work_directory(opts)
  Lydown::CLI::Support.detect_filename(opts)

  Lydown::CLI::Proofing.start_proofing(opts)
end

#translate(*args) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/lydown/cli/commands.rb', line 110

def translate(*args)
  require 'lydown'

  opts = Lydown::CLI::Support.copy_options(options)
  opts[:path] = args.first || '.'

  Lydown::CLI::Translation.process(opts)
end

#versionObject



10
11
12
13
14
15
16
17
18
# File 'lib/lydown/cli/commands.rb', line 10

def version
  require 'lydown/version'
  $stderr.puts "Lydown version #{Lydown::VERSION}"
  
  lilypond_version = Lydown::Lilypond.detect_lilypond_version(false)
  if lilypond_version
    $stderr.puts "Lilypond version #{lilypond_version}"
  end
end