Commit 7ac5c69e authored by Brian Long's avatar Brian Long
Browse files

refactored/tested

parent c987bc72
Loading
Loading
Loading
Loading

buxfer-cli/.gitignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
# Personal
buxfer-personal.properties

buxfer-cli/pom.xml

0 → 100644
+110 −0
Original line number Diff line number Diff line
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<artifactId>buxfer-cli</artifactId>
	<name>Buxfer CLI</name>

	<parent>
		<groupId>com.inteligr8.buxfer</groupId>
		<artifactId>buxfer-public-rest-parent</artifactId>
		<version>1.0-SNAPSHOT</version>
		<relativePath>../</relativePath>
	</parent>

	<properties>
		<jaxrs.impl>jersey</jaxrs.impl>
		<spring.version>5.2.14.RELEASE</spring.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>commons-cli</groupId>
			<artifactId>commons-cli</artifactId>
			<version>1.5.0</version>
		</dependency>
		<dependency>
			<groupId>${project.parent.groupId}</groupId>
			<artifactId>buxfer-public-rest-client</artifactId>
			<version>${project.parent.version}</version>
			<classifier>jersey</classifier>
		</dependency>
		<dependency>
			<groupId>com.inteligr8.polygon</groupId>
			<artifactId>polygon-public-rest-client</artifactId>
			<version>1.0-SNAPSHOT</version>
			<classifier>jersey</classifier>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jersey.core</groupId>
			<artifactId>jersey-client</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jersey.ext</groupId>
			<artifactId>jersey-proxy-client</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jersey.inject</groupId>
			<artifactId>jersey-hk2</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.glassfish.jersey.media</groupId>
			<artifactId>jersey-media-json-jackson</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.logging.log4j</groupId>
			<artifactId>log4j-slf4j-impl</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.httpcomponents</groupId>
			<artifactId>httpclient</artifactId>
			<version>4.5.9</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	
	<build>
		<plugins>
			<!-- This plugin causes the packaging of a JAR with embedded dependencies -->
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<version>3.3.0</version>
				<executions>
					<execution>
						<id>main-jar</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
						<configuration>
							<archive>
								<manifest>
									<mainClass>com.inteligr8.buxfer.CLI</mainClass>
								</manifest>
							</archive>
							<descriptorRefs>
								<descriptorRef>jar-with-dependencies</descriptorRef>
							</descriptorRefs>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
+16 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
  	<Logger name="com.inteligr8.buxfer" level="info" additivity="false">
  	  <AppenderRef ref="Console" />
  	</Logger>
    <Root level="warn">
      <AppenderRef ref="Console" />
    </Root>
  </Loggers>
</Configuration>
+9 −0
Original line number Diff line number Diff line
package com.inteligr8.buxfer;

import com.inteligr8.buxfer.model.Transaction;

public interface BuxferTransactionParser {
	
	ParsedTransaction parse(Transaction buxferTx) throws InterruptedException;

}
+64 −0
Original line number Diff line number Diff line
package com.inteligr8.buxfer;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class CLI {
	
	public static void main(String[] args) throws ParseException, IOException, InterruptedException {
		Options options = new Options();
		if (args.length == 0) {
			help(options, null, null, "A function is required");
			return;
		} else if (args[0].equals("help")) {
			help(options, null, null);
			return;
		}
		
		String func = args[0];
		String[] subargs = Arrays.copyOfRange(args, 1, args.length);
		
		switch (func.toLowerCase()) {
			case "investdetail":
				InvestNormalizeCLI.main(subargs);
				break;
			case "investgl":
				InvestGainsLossesCLI.main(subargs);
				break;
			case "writer":
				WriterCLI.main(subargs);
				break;
			default:
				help(options, null, null, "The function '" + func + "' is not valid");
		}
	}
	
	static void help(Options options, String extraCommand, List<String> extraLines, String message) {
		System.err.println(message);
		help(options, extraCommand, extraLines);
	}
	
	static void help(Options options, String extraCommand, List<String> extraLines) {
		System.out.println("A set of Buxfer tools");
		System.out.print("usage: java -jar buxfer-cli-*.jar");
		System.out.print(" ( InvestDetail | InvestGL | Writer )");
		if (extraCommand != null)
			System.out.print(" " + extraCommand);
		System.out.println();
		HelpFormatter help = new HelpFormatter();
		help.printOptions(new PrintWriter(System.out, true), 120, options, 3, 3);
		System.out.println("InvestDetail: Reformats descriptions and sets the appropriate transaction types for investments");
		System.out.println("    InvestGL: After 'InvestDetail', compute gains as transactions and reconcile");
		System.out.println("      Writer: Writes transactions to external file");
		if (extraLines != null)
			for (String extraLine : extraLines)
				System.out.println(extraLine);
	}

}
Loading