Skip to content

Commit

Permalink
Implement exec command #12
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobrasolin committed Nov 18, 2021
1 parent 8bdaefe commit 6da765e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand All @@ -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.
Expand Down
19 changes: 13 additions & 6 deletions lib/mnogootex/cfg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
19 changes: 14 additions & 5 deletions lib/mnogootex/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'] }
Expand Down
4 changes: 0 additions & 4 deletions lib/mnogootex/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# This is the default configuration file
spinner: ⣾⣽⣻⢿⡿⣟⣯⣷
commandline:
- latexmk
- -pdf
- --interaction=nonstopmode
work_path: null
8 changes: 6 additions & 2 deletions lib/mnogootex/job/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6da765e

Please sign in to comment.