diff --git a/Gemfile b/Gemfile index 8c796e6..d9a2176 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" gem "httpclient", "~>2.7.1" gem "ruby-progressbar", "~>1.7.5" -gem "thor", "~>0.19.1" +gem "thor", "~>0.20.0" gem "directory_watcher", "1.5.1" gem "rugged", ">=0.23.0", platforms: [:ruby] diff --git a/Gemfile.lock b/Gemfile.lock index 2a9e072..578958c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,7 +19,7 @@ GEM rspec-support (3.2.2) ruby-progressbar (1.7.5) rugged (0.23.0) - thor (0.19.1) + thor (0.20.0) PLATFORMS ruby @@ -30,7 +30,7 @@ DEPENDENCIES rspec (= 3.2.0) ruby-progressbar (~> 1.7.5) rugged (>= 0.23.0) - thor (~> 0.19.1) + thor (~> 0.20.0) BUNDLED WITH 1.11.2 diff --git a/docs/user-guide.md b/docs/user-guide.md index 393fec4..9ea19d2 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -463,7 +463,18 @@ Compiles Lilypond source files. This command is synonymous to running `lilypond` - `--force-version`/`-F`: use Lilypond version specified in user file - `--install`/`-n`: install version of Lilypond if not found (if the required version was overriden using any of `--env`, `--force-version` or `--use`) -- `--open`/`-O`: open output file after compilation +- `--music=`/`-M`: compile the given Lilypond code: + +```bash +$ lyp c -M"c'4 e' g' e' c'1" -o test +``` + +- `--music-relative=`/`-m`: compile the given Lilypond code in relative pitch: + +```bash +$ lyp c -m"c4 e g e c1" -o test +``` + - `--raw`/`-R`: run Lilypond "raw" (no pre-processing of dependencies) - `--require=PACKAGE`/`-rPACKAGE`: preload the specified package @@ -489,11 +500,26 @@ Shows dependencies for a given source file. ### lyp exec -Synopsis: `lyp exec SCRIPT ...` +Synopsis: `lyp exec ... SCRIPT ...` Shorthand: `lyp x` -Runs a Lilypond script (using the currently selected version of Lilypond). +Runs a Lilypond script (using the currently selected version of Lilypond). The `exec` command accepts the following options: + +- `--env`/`-E`: use the Lilypond version specified in the `LILYPOND_VERSION` environment variable: + + ```bash + $ LILYPOND_VERSION=2.19.50 lyp x midi2ly ... + ``` + +- `--install`/`-n`: install version of Lilypond if not found (if the required version was overriden using any of `--env`, `--force-version` or `--use`) +- `--use=VERSION`/`-uVERSION`: use the given version of Lilypond: + + ```bash + $ lyp x -u2.19.53 midi2ly... + # automatically install given version of Lilypond + $ lyp c -nu2.19.53 midi2ly ... + ``` ### lyp flatten @@ -507,7 +533,12 @@ Synopsis: `lyp install PACKAGE|lilypond@VERSION` Shorthand: `lyp i` -Installs a package or a Lilypond. See installing packages and installing versions of Lilypond above. +Installs a package or a Lilypond. See installing packages and installing versions of Lilypond above. The `install` command accepts the following options: + +- `--default`/`-d`: make the version to install the default version (when installing Lilypond) +- `--dev`: install the current working directory as a development package +- `--test`/`-t`: run package tests after installation (when installing a package) +- `--update`/`-u`: remove any old versions (when installing a package) ### lyp list diff --git a/lib/lyp/cli.rb b/lib/lyp/cli.rb index 91cc54e..4a56539 100644 --- a/lib/lyp/cli.rb +++ b/lib/lyp/cli.rb @@ -54,7 +54,7 @@ class Lyp::CLI < Thor "w" => :watch, "x" => :exec - check_unknown_options! :except => [:compile, :watch, :benchmark] + check_unknown_options! :except => [:compile, :exec, :watch, :benchmark] class_option :verbose, aliases: '-V', :type => :boolean, desc: 'show verbose output' no_commands do @@ -129,9 +129,10 @@ def cleanup def compile(*argv) opts, argv = Lyp::Lilypond.preprocess_argv(argv) opts[:verbose] ||= options[:verbose] + argv.unshift('-V') if options[:verbose] $cmd_options = opts - lilypond_path = Lyp::Lilypond.select_lilypond_version(opts, argv.last) + Lyp::Lilypond.select_lilypond_version(opts, argv.last) $stderr.puts "Lyp #{Lyp::VERSION}" unless opts[:mode] == :quiet Lyp::System.test_installed_status! @@ -156,7 +157,15 @@ def deps(fn) desc "exec [...]", "Execute a lilypond script" def exec(*argv) - $stderr.puts "Lyp #{Lyp::VERSION}" + opts, argv = Lyp::Lilypond.preprocess_bin_script_argv(argv) + opts[:verbose] ||= options[:verbose] + $cmd_options = opts + + $cmd_options = opts + + Lyp::Lilypond.select_lilypond_version(opts, argv.last) + + $stderr.puts "Lyp #{Lyp::VERSION}" unless opts[:mode] == :quiet Lyp::System.test_installed_status! Lyp::Lilypond.invoke_script(argv, {}) end diff --git a/lib/lyp/lilypond.rb b/lib/lyp/lilypond.rb index be63c84..bfce47a 100644 --- a/lib/lyp/lilypond.rb +++ b/lib/lyp/lilypond.rb @@ -66,6 +66,8 @@ def parse_lilypond_arg(arg, argv, argv_clean, options) when '-S', '--snippet' argv_clean.concat ['-dbackend=eps', '-daux-files=#f', '--png', '-dresolution=600'] options[:snippet_paper_preamble] = true + when '--svg' + argv_clean.concat ['-dbackend=svg'] when '-u', '--use' options[:use_version] = argv.shift when '-V', '--verbose' @@ -75,13 +77,50 @@ def parse_lilypond_arg(arg, argv, argv_clean, options) options[:mode] = :system when '--invoke-quiet' options[:mode] = :quiet - when '--svg' - argv_clean.concat ['-dbackend=svg'] else argv_clean << arg end end + def preprocess_bin_script_argv(argv) + options = {} + argv = argv.dup # copy for iterating + argv_clean = [] + while arg = argv.shift + parse_lilypond_bin_script_arg(arg, argv, argv_clean, options) + end + + [options, argv_clean] + end + + def parse_lilypond_bin_script_arg(arg, argv, argv_clean, options) + case arg + when ARGUMENT_EQUAL_REGEXP + argv.insert(0, "--#{$1}", $2) + when ARGUMENT_SHORTHAND_REGEXP + argv.insert(0, "-#{$1}", $2) + when NO_ARGUMENT_SHORTHAND_REGEXP + tmp_args = [] + $1.each_char {|c| tmp_args << "-#{c}"} + tmp_args << "-#{$2}" + argv.insert(0, *tmp_args) + when '-E', '--env' + unless ENV['LILYPOND_VERSION'] + raise "$LILYPOND_VERSION not set" + end + options[:use_version] = ENV['LILYPOND_VERSION'] + when '-n', '--install' + options[:install] = true + when '-u', '--use' + options[:use_version] = argv.shift + when '--invoke-system' + options[:mode] = :system + else + argv_clean << arg + argv_clean += argv + end + end + def prepare_inline_music_file(music, opts = {}) filename = Lyp.tmp_filename('.ly') File.open(filename, 'w+') do |f| @@ -149,6 +188,10 @@ def compile(argv, opts = {}) def invoke(argv, opts = {}) lilypond = current_lilypond + if opts[:verbose] + puts "#{lilypond} #{argv.join(" ")}" + end + case opts[:mode] when :system system("#{lilypond} #{argv.join(" ")}")