#!/usr/bin/env --split-string=${JDK_HOME}/bin/java @building/Makeshift/java_arguments @building/Makeshift/java_javac_arguments \c [SS] package Breccia.Web.imager; // [AFN] // This command runs directly from the present source file, it needs no compiling. import Breccia.parser.plain.BrecciaCursor; import Breccia.XML.translator.BrecciaXCursor; import java.io.IOException; import java.io.PrintStream; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import static Breccia.Web.imager.ImagingCommands.image; import static Breccia.Web.imager.Project.projectOutputDirectory; import static java.lang.System.err; import static java.lang.System.exit; /** A shell command to make a Web image. * * @see * The `breccia-web-image` command */ public final class BrecciaWebImageCommand implements AutoCloseable { // [AFN] /** @param argsN Nominal arguments, aka options. * @param argsP Positional arguments. */ private BrecciaWebImageCommand( final List argsN, final List argsP ) { opt.initialize( argsN ); final int n = argsP.size(); if( n != 1 ) { err.println( commandName + ": Expecting 1 argument, found " + n ); exitWithUsage( err, 1 ); } boundaryPath = Path.of(argsP.get(0)).toAbsolutePath().normalize(); } /** Takes a `breccia-web-image` command from the shell and executes it. */ public static void main( final String[] arguments ) { final var argsN = new ArrayList(); final var argsP = new ArrayList(); for( final String arg: arguments ) { exitOnDemand( arg ); (arg.charAt(0) == '-' ? argsN : argsP).add( arg ); } try( final var command = new BrecciaWebImageCommand( argsN, argsP )) { if( !command.run() ) exit( 1 ); }} // ━━━ A u t o C l o s e a b l e ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ public @Override void close() { sourceXCursor.close(); } //// P r i v a t e //////////////////////////////////////////////////////////////////////////////////// private final Path boundaryPath; private static final String commandName = "breccia-web-image"; private static void exitOnDemand( final String arg ) { if( arg.equals("-?") || arg.equals("-help") ) exitWithUsage( System.out, 0 ); } private static void exitWithUsage( final PrintStream sP, final int status ) { sP.println( "Usage: " + commandName + " [] " ); sP.println( " " + commandName + " -help | -?" ); sP.println( "Options, one or more of:" ); sP.println( " -author-home-directory=" ); sP.println( " -centre-column=" ); sP.println( " -co-service-directory=" ); sP.println( " -exclude=" ); sP.println( " -fake" ); sP.println( " -force" ); sP.println( " -glyph-test-font= | none" ); sP.println( " -math" ); sP.println( " -reference-mapping=;;; [|| ;;;] ..." ); sP.println( " -speak" ); sP.println( " -stifle" ); sP.println( " -verbosity=0|1|2" ); exit( status ); } private final ImagingOptions opt = new ImagingOptions( commandName ); /** @return True on success, false on failure. */ private boolean run() { return image( commandName, boundaryPath, opt, new TranslatorMaker(), projectOutputDirectory ); } private final BrecciaXCursor sourceXCursor = new BrecciaXCursor(); // ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ private final class TranslatorMaker implements FileTranslator.Maker { public @Override FileTranslator newTranslator( ImageMould mould ) { return new BreccianFileTranslator<>( new BrecciaCursor(), sourceXCursor, mould ); }}} // NOTES // ───── // AFN Atypical file naming is allowed here. ‘The compiler does not enforce the optional restriction // defined at the end of JLS §7.6, that a type in a named package should exist in a file whose // name is composed from the type name followed by the .java extension.’ // http://openjdk.java.net/jeps/330 // https://docs.oracle.com/javase/specs/jls/se15/html/jls-7.html#jls-7.6 // // SS · Here the long form `--split-string` (as opposed to `-S`) enables Emacs to recognize this file // as Java source code. See the note apropos of ‘source-launch files encoded with a shebang’ at // `http://reluk.ca/project/Java/Emacs/jmt-mode.el`. // Copyright © 2020-2023 Michael Allan. Licence MIT.