Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problematic invocation: unknown argument '--debug' #51

Open
b00693303 opened this issue Dec 18, 2024 · 9 comments
Open

Problematic invocation: unknown argument '--debug' #51

b00693303 opened this issue Dec 18, 2024 · 9 comments

Comments

@b00693303
Copy link

b00693303 commented Dec 18, 2024

Hello,

thanks again for this fantastic tool.

I have a few issue initialising it on my Mac M1:
the debug invocation is mysteriously buggy and prevents completely the use of Scrivomatic...

=== ------------------------------------------------------ ===
=== Scrivomatic V1.0.36 Report @ 2024-12-18 19:16:16 +0100 ===
=== ------------------------------------------------------ ===
Running shell: /bin/zsh
Working directory: /Users/xxx/Downloads/testscrivomatic1.md
Initiating with Ruby 2.6.10
===------ Input Options: ------===
#<struct Scrivomatic::OPT input="testscrivomatic1.md", output=nil, to=nil, yaml="pandocomatic.yaml", command="pandocomatic", envpath="/Users/xxx/bin:/Users/xxx/.rbenv/shims:/Library/TeX/texbin:/opt/homebrew/bin:/usr/local/bin", build=false, cleanup=false, verbose=true, dry_run=false, open_log=true, data_dir=nil>
===------ Final ENV PATH: ------===
/Users/xxx/bin:/Users/xxx/.rbenv/shims:/Library/TeX/texbin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/Scrivener.app/Contents/Resources/MultiMarkdown/bin
===------ TOOL PATHS: ------===
---pandoc: /opt/homebrew/bin/pandoc | V: 3.6
---ruby: /Users/xxx/.rbenv/shims/ruby | V: ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin24]
---pandocomatic: /Users/xxx/.rbenv/shims/pandocomatic | V: 2.0.1
---paru library: V: 1.4.1
---rbenv versions:
system

  • 3.2.0 (set by /Users/xxx/.rbenv/version)
    ---rbenv: /opt/homebrew/bin/rbenv
    ---gem: /Users/xxx/.rbenv/shims/gem
    ---xelatex: /Library/TeX/texbin/xelatex
    ---latexmk: /Library/TeX/texbin/latexmk

… running pandocomatic, please wait …
===------ COMMAND OUTPUT: ------===
:: Running: /Users/xxx/.rbenv/shims/pandocomatic -c pandocomatic.yaml --debug testscrivomatic1.md
::: Problematic invocation: unknown argument '--debug'.
:: exit status: pid 16758 exit 243

!!!---scrivomatic::runCommand() RETURN non-zero value: /Users/xxx/.rbenv/shims/pandocomatic -c pandocomatic.yaml --debug testscrivomatic1.md !!!

@Merovex
Copy link

Merovex commented Dec 18, 2024 via email

@b00693303
Copy link
Author

b00693303 commented Dec 18, 2024

yes, even with --enable pandoc-verbose (the pandocomatic equivalent)

@Merovex
Copy link

Merovex commented Dec 18, 2024 via email

@b00693303
Copy link
Author

b00693303 commented Dec 18, 2024

thanks for your help! here is the configuration (it's the standard one)

#!/usr/bin/env ruby
# encoding: utf-8

# scrivomatic is a wrapper script that adds tools to the path (as Scrivener
# does not use the user's path), and enables some other tweaks to optimise
# the workflow when scrivener calls pandocomatic.
# `scrivomatic --help` for details…

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

require 'open3' # ruby standard library class to handle stderr and stdout
require 'optparse' # ruby standard option parser
require 'fileutils' # ruby standard library to deal with files
require 'shellwords' # escapes strings to run in the shell

##
# main scrivomatic class
class Scrivomatic
	##
	# Sets up the path and performs other functions to improve running
	# pandocomatic from scrivener...
	attr_accessor :options
	attr_reader :version, :cmd, :runLog
	VER = '1.0.36'.freeze
	OPT = Struct.new(:input, :output, :to, :yaml, :command, :envpath, :build, :cleanup, :verbose, :dry_run, :open_log, :data_dir)
	DEFENVPATH = ENV['HOME'] + '/bin'

	#-------------------------------class constructor
	def initialize
		@options = OPT.new(nil, nil, nil, nil, 'pandocomatic', DEFENVPATH, false, false, false, false, false, nil)
		@version = VER
		@fileext = ''
		@cmd = ''
		@toolPath = ''
		@runLog = ''
		@latexEngine = 'xelatex'
	end

	#-------------------------------run all options
	def run
		preBuild # removes old tex file if we are building
		makePath # build the path
		printInfo # print some information
		buildCommand # build the pandoc[omatic] command
		runCommand # run the pandoc[omatic] command
		postBuild # run latexmk if we are building
	end

	#--------------------------------if we will run latexmk, remove old tex file before running pandoc
	def preBuild
		return unless options.build && !(options.dry_run)
		texPath = options.input.gsub(/#{@fileext}$/, '.tex')
		texFile = texPath.gsub(/\\+/, '')
		if File.exist?(texFile)
			puts "\n===------ Delete OLD TeX File: #{texFile}: ------===" if @options[:verbose] == true
			system("latexmk -quiet -c #{texFile} >/dev/null 2>&1")
			File.delete(texFile)
		end
	end

	#-------------------------------make env path
	def makePath
		home = ENV['HOME'] + '/'
		pathtest = [home+'/.rbenv/shims', 
			'/usr/local/opt/ruby/bin', '/usr/local/lib/ruby/gems/2.7.0/bin', 
			home+'Library/TinyTeX/bin/universal-darwin', '/Library/TeX/texbin', 
			'/opt/homebrew/bin', '/usr/local/bin', 
			home+'/anaconda/bin', home+'/anaconda3/bin',
			home+'/miniconda/bin', home+'/miniconda3/bin', home+'/micromamba/bin',
			home+'/.cabal/bin', home+'/.local/bin', 
			rvm_check]
		pathtest.each { |p| @options[:envpath] = @options[:envpath] + ':' + p if File.directory?(p) }
		ENV['LANG'] = 'en_GB.UTF-8' if ENV['LANG'].nil? # Just in case we have no LANG, which breaks UTF8 encoding
		@options[:envpath].gsub!(%r{(//)}, '/') # remove double slash
		@options[:envpath].gsub!(/(::)/, ':') # remove double colon
		@options[:envpath].gsub!(/:$/, '') # remove final colon
		ENV['PATH'] = @options[:envpath] + ':' + ENV['PATH']
	end # end makePath()

	#-------------------------------print initial report
	def printInfo
		return if @options[:verbose] == false
		puts "\n=== ------------------------------------------------------ ==="
		puts '=== Scrivomatic V' + @version + ' Report @ ' + Time.now.to_s + ' ==='
		puts '=== ------------------------------------------------------ ==='
		puts ' Running shell: ' + `printf $SHELL`
		puts ' Working directory: ' + `pwd`
		puts " Initiating with Ruby #{RUBY_VERSION}"
		puts '===------ Input Options: ------==='
		puts @options
		puts '===------ Final ENV PATH: ------==='
		puts ENV['PATH']
		puts '===------ TOOL PATHS: ------==='
		puts `echo "---pandoc: $(which pandoc) | V: $(pandoc -v | sed -nE '1 s/^pandoc // gp')"`
		puts `echo "---ruby: $(which ruby) | V: $(ruby -v)"`
		puts '!--ruby version incompatible with new pandocomatic, see https://github.com/iandol/scrivomatic/blob/master/Installing-Ruby.md' if `ruby -v` =~ /ruby 2\.3\.\d/
		puts `echo "---pandocomatic: $(which pandocomatic) | V: $(pandocomatic -v | sed -En '1s/^Pandocomatic version /''/p')"`
		puts '---paru library: V: ' + `ruby -e 'require "paru"; puts Paru::VERSION.join(".")'`
		puts `echo "---rbenv versions:"; [[ -x $(which rbenv) ]] && rbenv versions`
		%w[rbenv rvm gem panzer python xelatex latexmk].each do |c|
			location = `which #{c}`.chomp
			puts "---#{c}: #{location}" unless location.empty?
		end
		puts "\n … running #{@options[:command]}, please wait …\n"
	end

	#-------------------------------build the command line
	def buildCommand
		@cmd += ' --data-dir="' + @options[:data_dir] + '"' unless @options[:data_dir].nil?
		@cmd += ' --output ' + @options[:output] + ' ' unless @options[:output].nil?
		@cmd += ' --to "' + @options[:to] + '"' unless @options[:to].nil?
		@cmd += ' -c ' + @options[:yaml] if !@options[:yaml].nil? && @options[:command] == 'pandocomatic'
		@cmd += ' --debug' if @options[:verbose] == true && @options[:command] == 'pandocomatic'
		@cmd += ' ---debug "panzerlogs"' if @options[:verbose] == true && @options[:command] == 'panzer'
		@toolPath = `which #{@options[:command]}`.chomp
		@cmd = @toolPath + @cmd + ' ' + @options[:input] + ' ' unless @options[:input].nil?
	end

	#-------------------------------run the command
	def runCommand
		`open scrivomatic.log` if @options[:open_log] && File.exist?('scrivomatic.log')
		puts '===------ COMMAND OUTPUT: ------===' if @options[:verbose] == true
		if File.exist?(@toolPath) && !options.dry_run
			puts ":: Running: #{@cmd}\n" if @options[:verbose] == true
			Open3.popen2e(@cmd) do |_stdin, oe, thread|
				while (line = oe.gets)
					puts '::: ' + line.chomp if @options[:verbose] == true
					check_engine = line.match(/pdf-engine=(\w+)/)
					@latexEngine = check_engine[1] unless check_engine.nil?
				end
				exit_status = thread.value
				puts ':: exit status: ' + exit_status.to_s if @options[:verbose] == true
				unless exit_status.success?
					puts "\n!!!---scrivomatic::runCommand() RETURN non-zero value: #{cmd}!!!"
				end
			end
		elsif !options.dry_run
			puts "Tool doesn't exist!!!" if @options[:verbose] == true
			puts "\n!!!---scrivomatic::runCommand() Couldn't find #{@toolPath} to run, please supply a proper path!"
		elsif @options[:verbose] == true
			puts 'Dry run, nothing actually executed...'
		end
	end

	#-------------------------------parse inputs
	def parseInputs(_arg)
		optparse = OptionParser.new do |opts|
			opts.banner = 'Scrivomatic V' + @version + "\n"
			opts.banner += "=======================\n"
			opts.banner += "Scrivomatic is a wrapper around pandocomatic or panzer, that sets up the environment path, enforces UTF8 encoding and other settings so they can be run from any other process that may not do this (e.g. Scrivener).\n\n"
			opts.banner += 'Usage: scrivomatic [additional options] FILE'
			opts.on('-i', '--input FILE', 'Input file') do |v|
				v.gsub!(/(\A'|'\Z)/, '')
				@options[:input] = v.shellescape
				@fileext = Regexp.escape(File.extname(@options[:input]))
			end
			opts.on('-o', '--output [file]', 'Output file. Optional for pandocomatic.') do |v|
				@options[:output] = v.shellescape
			end
			opts.on('-t', '--to [format]', 'Pandoc Format. Optional for pandocomatic.') do |v|
				@options[:to] = v
			end
			opts.on('-y', '--yaml [file]', 'Specify which YAML file for pandocomatic.') do |v|
				@options[:yaml] = v.strip.shellescape
			end
			opts.on('-c', '--command [command]', 'Tool to use: [pandocomatic] | panzer') do |v|
				@options[:command] = v
			end
			opts.on('-p', '--path [dirpath]', 'Additional Path to Search for Commands.') do |v|
				@options[:envpath] = v.strip.shellescape + ':' + @options[:envpath]
			end
			opts.on('-b', '--build', 'For LaTeX output, run latexmk') do |v|
				@options[:build] = v
			end
			opts.on('-B', '--buildclean', 'For LaTeX output, run latexmk and cleanup') do |v|
				@options[:build] = v
				@options[:cleanup] = v
			end
			opts.on('-d', '--dry-run', 'Dry run.') do |v|
				@options[:dry_run] = v
			end
			opts.on('-z', '--data-dir [file]', 'Pandoc data dir.') do |v|
				@options[:data_dir] = v.strip.shellescape
			end
			opts.on('-v', '--[no-]verbose', 'Verbose output.') do |v|
				@options[:verbose] = v
			end
			opts.on('-l', '--[no-]log', 'View log in Console.app.') do |v|
				@options[:open_log] = v
			end
			opts.on('-h', '--help', 'Prints this help!') do
				puts optparse
				exit(0)
			end
		end # end OptionParser

		optparse.parse!

		# make sure we have an input file
		return unless @options[:input].nil?

		# otherwise check if we got passed the file
		if ARGV.nil? || ARGV[0].nil?
			puts optparse
			abort "\n\n!!!---scrivomatic::parseInputs requires valid input file: --input"
		else
			v = ARGV[0].gsub(/(\A'|'\Z)/, '') # scrivener sometimes passes the file wrapped in '
			@options[:input] = v.shellescape # we assume it was passed without -i flag
			@fileext = Regexp.escape(File.extname(@options[:input]))
		end
	end # end parseInputs

	#-------------------------------check for RVM
	def rvm_check
		rvm_home = ENV['HOME'] + '/.rvm'
		return '' unless File.directory?(rvm_home)
		rvm_home + '/wrappers/default'
	end

	#------------------------------check if we want to run latexmk
	def postBuild
		return unless options.build && !(options.dry_run)
		texPath = options.input.gsub(/#{@fileext}$/, '.tex')
		texFile = texPath.gsub(/\\+/, '')
		pdfFile = texPath.gsub(/\.tex/, '.pdf')
		if File.exist?(texFile)
			if File.exist?(pdfFile)
				puts "\n===------ Remove old #{pdfFile} ------===" if @options[:verbose] == true
				File.delete(pdfFile)
			end
			puts "\n===------ RUN LATEXMK on #{texPath}: ------===" if @options[:verbose] == true
			@latexEngine = 'pdf' if @latexEngine =~ /pdflatex/
			xcmd = "latexmk -logfilewarnings -interaction=nonstopmode -f -pv -time -#{@latexEngine} -f #{texPath}"
			puts ":: directory: #{Dir.pwd}" if @options[:verbose] == true
			puts ":: command: #{xcmd}" if @options[:verbose] == true
			begin
				Open3.popen2e(xcmd) do |_stdin, oe, wait_thr|
					while (line = oe.gets)
						if line.chomp.to_s =~ /^(Latexmk:|Run|LaTeX|This is|===|Accumulated|Missing|! )/
							puts '::: ' + line.chomp if @options[:verbose] == true
						end
					end
					exit_status = wait_thr.value
					puts ':: exit status: ' + exit_status.to_s if @options[:verbose] == true
					if exit_status.success? && @options[:cleanup] == true
						logPath = File.basename(options.input, '.*') + '.log'
						FileUtils.cp(logPath, 'latexlog_' + logPath) if File.file?(logPath)
						`latexmk -C -quiet`
						puts ":: Clean-up: used latexmk -c, but kept the latex build log as #{'latexlog_' + logPath}" if @options[:verbose] == true
					elsif !exit_status.success?
						puts "!!!---Scrivomatic: errors on build #{xcmd}, check logs!!!"
					end
				end
			rescue StandardError => e
				puts e
			end
		else
			puts "!!!---Scrivomatic postBuild: could not find #{texPath}"
		end
	end
end #--------------- end Scrivomatic class

scriv = Scrivomatic.new
scriv.parseInputs(ARGV)
scriv.run

@iandol
Copy link
Owner

iandol commented Dec 19, 2024

Hi, pandocomatic V2.x has changed debug and added logging: https://github.com/htdebeer/pandocomatic/releases/tag/2.0.0 — scrivomatic hasn't yet been updated to handle these changes. Possibly reverting to < 2 would be a stop gap.

I didn't have much time to test, but will definitely need to adjust scrivomatic's handling of logging (it currently tries to capture everything it can, but perhaps we can take advantage of pandocomatic doing this now), and adjust to pandocomatic's debug flag changes. I will try to have a look in the next couple of days.

@iandol
Copy link
Owner

iandol commented Dec 22, 2024

I just tested and I couldn't reproduce, though I have a slightly modified scrivomatic (I've switched to use pixi over rbenv, but this shouldn't impact pandocomatic directly). I'll release my current version and you can test. I am using -v to trigger pandocomatic's --log command. But pandocomatic's behaviour has changed a bit and it uses --enable pandoc-verbose to make pandoc verbose but I can't quite see this output in scrivomatic log anymore...

@iandol
Copy link
Owner

iandol commented Dec 22, 2024

Try V1.0.40, though I am cannot see any of Pandoc's verbose output itself, this may be a pandocomatic V2.0 issue? htdebeer/pandocomatic#118

@b00693303
Copy link
Author

Thanks! I will give it a try at the end of next week :-)
Have a great end of year holidays!

@iandol
Copy link
Owner

iandol commented Dec 22, 2024

OK, let me know if it works. Issue #118 was resolved (it was my mistake, not a pandocomatic problem) and so as long as you add verbose: true then you get full output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants