From 6da765e52c89bc2cf9d9955f9b5e0ef9eb29b4bd Mon Sep 17 00:00:00 2001 From: Paolo Brasolin Date: Thu, 18 Nov 2021 14:36:40 +0100 Subject: [PATCH] Implement exec command #12 --- README.md | 13 +------------ lib/mnogootex/cfg.rb | 19 +++++++++++++------ lib/mnogootex/cli.rb | 19 ++++++++++++++----- lib/mnogootex/defaults.yml | 4 ---- lib/mnogootex/job/warden.rb | 8 ++++++-- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 679754d..c7e20f3 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ a configuration file in your home folder and use it as a global configuration for all you projects, while overwriting only specific options in the configuration files of each one. -Многоꙮтех currently accepts three options. +Многоꙮтех currently accepts two options. #### `spinner` @@ -143,17 +143,6 @@ animate the spinners for the command line interface. # Default value: spinner: ⣾⣽⣻⢿⡿⣟⣯⣷ -#### `commandline` - -This option is an array of the components for the commandline used -to compile documents. - - # Default value: - commandline: - - latexmk - - -pdf - - --interaction=nonstopmode - #### `work_path` This option is an override for the path where compilation happens. diff --git a/lib/mnogootex/cfg.rb b/lib/mnogootex/cfg.rb index 77935ec..41e3d82 100644 --- a/lib/mnogootex/cfg.rb +++ b/lib/mnogootex/cfg.rb @@ -25,15 +25,22 @@ def self.recombobulate(*args) class << self private + def split_jobs_and_flags(args) + flags = args.drop_while { |arg| !arg.start_with?('-') }.unless(&:empty?) + jobs = args.take_while { |arg| !arg.start_with?('-') }.unless(&:empty?) + # TODO: some kind of validation? + [jobs, flags] + end + def try_args(*args) main = Pathname.new(args.fetch(-1, '')) return unless main.file? main = main.realpath cfg = load_descending(pathname: main.dirname, basename: BASENAME) - jobs = args[0..-2].unless(&:empty?) + jobs, flags = split_jobs_and_flags(args[0..-2]) - [jobs, main, cfg] + [jobs, flags, main, cfg] end def try_link(*args) @@ -42,9 +49,9 @@ def try_link(*args) main = link.readlink.realpath cfg = load_descending(pathname: main.dirname, basename: BASENAME) - jobs = args + jobs, flags = split_jobs_and_flags(args) - [jobs, main, cfg] + [jobs, flags, main, cfg] end def try_cfgs(*args) @@ -53,9 +60,9 @@ def try_cfgs(*args) cfg = load_descending(pathname: yaml.dirname, basename: BASENAME) main = yaml.dirname.join(cfg.fetch('main', '')).if(&:file?)&.realpath - jobs = args + jobs, flags = split_jobs_and_flags(args) - [jobs, main, cfg] + [jobs, flags, main, cfg] end end end diff --git a/lib/mnogootex/cli.rb b/lib/mnogootex/cli.rb index be72ca9..66a28f3 100644 --- a/lib/mnogootex/cli.rb +++ b/lib/mnogootex/cli.rb @@ -31,15 +31,24 @@ def clobber desc 'go [JOB ...] [MAIN]', 'Run each (or every) JOB for MAIN (or inferred) document' def go(*args) - _, main, cfg = Mnogootex::Cfg.recombobulate(*args) - cfg = Mnogootex::Cfg::DEFAULTS.merge cfg - Mnogootex::Job::Warden.new(source: main, configuration: cfg).start + jobs, _, main, cfg = Mnogootex::Cfg.recombobulate(*args) + flags = ['-pdf', '-interaction=nonstopmode'] + cfg = Mnogootex::Cfg::DEFAULTS.merge(cfg).merge({ 'jobs' => jobs }.compact) + Mnogootex::Job::Warden.new(source: main, configuration: cfg, flags: flags).start + end + + desc 'exec [JOB ...] [LATEXMK_OPTION ...] [MAIN]', + 'Run each (or every) JOB for MAIN (or inferred) document' + def exec(*args) + jobs, flags, main, cfg = Mnogootex::Cfg.recombobulate(*args) + cfg = Mnogootex::Cfg::DEFAULTS.merge(cfg).merge({ 'jobs' => jobs }.compact) + Mnogootex::Job::Warden.new(source: main, configuration: cfg, flags: flags).start end desc 'dir [JOB] [MAIN]', 'Print dir of JOB (or source) for MAIN (or inferred) document' def dir(*args) - jobs, main, cfg = Mnogootex::Cfg.recombobulate(*args) + jobs, _, main, cfg = Mnogootex::Cfg.recombobulate(*args) if jobs.empty? puts main.dirname @@ -53,7 +62,7 @@ def dir(*args) desc 'pdf [JOB ...] [MAIN]', 'Print PDF path of each (or every) JOB for MAIN (or inferred) document' def pdf(*args) - jobs, main, cfg = Mnogootex::Cfg.recombobulate(*args) + jobs, _, main, cfg = Mnogootex::Cfg.recombobulate(*args) jobs = cfg['jobs'] if jobs.empty? jobs.map! { |hid| Mnogootex::Job::Porter.new hid: hid, source_path: main, work_path: cfg['work_path'] } diff --git a/lib/mnogootex/defaults.yml b/lib/mnogootex/defaults.yml index 3b1650e..18615a2 100644 --- a/lib/mnogootex/defaults.yml +++ b/lib/mnogootex/defaults.yml @@ -1,7 +1,3 @@ # This is the default configuration file spinner: ⣾⣽⣻⢿⡿⣟⣯⣷ -commandline: - - latexmk - - -pdf - - --interaction=nonstopmode work_path: null diff --git a/lib/mnogootex/job/warden.rb b/lib/mnogootex/job/warden.rb index 962eab6..8f87038 100644 --- a/lib/mnogootex/job/warden.rb +++ b/lib/mnogootex/job/warden.rb @@ -11,9 +11,12 @@ module Mnogootex module Job class Warden - def initialize(source:, configuration:) + LATEXMK_PATH = 'latexmk' + + def initialize(source:, configuration:, flags:) @source = source @configuration = configuration + @flags = flags @processor = nil @porters = [] @@ -81,7 +84,8 @@ def init_and_exec_logger # TODO: generalize, integrate with Runner def commandline(target_pathname) [ - *@configuration['commandline'], + LATEXMK_PATH, + *@flags, target_pathname.basename.to_s ] end