Skip to content

Commit

Permalink
Add command-line tools
Browse files Browse the repository at this point in the history
Affects: #73
  • Loading branch information
io7m committed Sep 29, 2024
1 parent b8efc09 commit 7a07a60
Show file tree
Hide file tree
Showing 14 changed files with 1,526 additions and 0 deletions.
142 changes: 142 additions & 0 deletions com.io7m.laurel.cmdline/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>

<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.io7m.laurel</groupId>
<artifactId>com.io7m.laurel</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>com.io7m.laurel.cmdline</artifactId>

<packaging>jar</packaging>
<name>com.io7m.laurel.cmdline</name>
<description>Image caption management (Command-line tools)</description>
<url>https://www.io7m.com/software/laurel/</url>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.io7m.laurel.filemodel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>com.io7m.laurel.model</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.io7m.quarrel</groupId>
<artifactId>com.io7m.quarrel.core</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.quarrel</groupId>
<artifactId>com.io7m.quarrel.ext.logback</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.quarrel</groupId>
<artifactId>com.io7m.quarrel.ext.xstructural</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.seltzer</groupId>
<artifactId>com.io7m.seltzer.api</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.jattribute</groupId>
<artifactId>com.io7m.jattribute.core</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.bundle</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Ignore dependencies that bytecode analysis gets wrong. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<failOnWarning>true</failOnWarning>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency> com.io7m.quarrel:com.io7m.quarrel.ext.xstructural::*</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>ch.qos.logback:logback-classic::*</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>

<plugin>
<groupId>com.io7m.stmp</groupId>
<artifactId>string-template-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-version</id>
<phase>generate-sources</phase>
<goals>
<goal>renderTemplate</goal>
</goals>
<configuration>
<template>
<inputFile>src/main/string-template/LCVersion.st</inputFile>
<name>LCVersion</name>
<outputFile>
${project.build.directory}/generated-sources/string-template/com/io7m/laurel/cmdline/LCVersion.java
</outputFile>
<properties>
<appVersion>${project.version}</appVersion>
<appBuild>${buildNumber}</appBuild>
</properties>
</template>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-sources</id>
<goals>
<goal>add-source</goal>
</goals>
<phase>
generate-sources
</phase>
<configuration>
<sources>
<source>
${project.build.directory}/generated-sources/string-template
</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright © 2024 Mark Raynsford <[email protected]> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.laurel.cmdline;

import com.io7m.laurel.cmdline.internal.LCExport;
import com.io7m.laurel.cmdline.internal.LCImport;
import com.io7m.quarrel.core.QApplication;
import com.io7m.quarrel.core.QApplicationMetadata;
import com.io7m.quarrel.core.QApplicationType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
* The command-line program.
*/

public final class LCMain implements Runnable
{
private static final Logger LOG =
LoggerFactory.getLogger(LCMain.class);

private final List<String> args;
private final QApplicationType application;
private int exitCode;

/**
* The main entry point.
*
* @param inArgs Command-line arguments
*/

public LCMain(
final String[] inArgs)
{
this.args =
Objects.requireNonNull(List.of(inArgs), "Command line arguments");

final var metadata =
new QApplicationMetadata(
"laurel",
"com.io7m.laurel",
LCVersion.MAIN_VERSION,
LCVersion.MAIN_BUILD,
"The laurel command-line application.",
Optional.of(URI.create("https://www.io7m.com/software/laurel/"))
);

final var builder = QApplication.builder(metadata);
builder.allowAtSyntax(true);
builder.addCommand(new LCImport());
builder.addCommand(new LCExport());

this.application = builder.build();
this.exitCode = 0;
}

/**
* The main entry point.
*
* @param args Command line arguments
*/

public static void main(
final String[] args)
{
System.exit(mainExitless(args));
}

/**
* The main (exitless) entry point.
*
* @param args Command line arguments
*
* @return The exit code
*/

public static int mainExitless(
final String[] args)
{
final LCMain cm = new LCMain(args);
cm.run();
return cm.exitCode();
}

/**
* @return The program exit code
*/

public int exitCode()
{
return this.exitCode;
}

@Override
public void run()
{
this.exitCode = this.application.run(LOG, this.args).exitCode();
}

@Override
public String toString()
{
return String.format(
"[LCMain 0x%s]",
Long.toUnsignedString(System.identityHashCode(this), 16)
);
}
}
Loading

0 comments on commit 7a07a60

Please sign in to comment.