All Downloads are FREE. Search and download functionalities are using the official Maven repository.

protoj.lang.internal.ProtoExecutableMain Maven / Gradle / Ivy

The newest version!
package protoj.lang.internal;

import java.io.File;
import java.util.Arrays;

import joptsimple.ArgumentAcceptingOptionSpec;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpecBuilder;
import protoj.lang.StandardProject;

/**
 * This is the entry point for the protoj executable jar.
 * 
 * @author Ashley Williams
 * 
 */
public final class ProtoExecutableMain {
	/**
	 * Performs the following jobs depending on the args parameter:
	 * 
    *
  • --sample option specified - causes a sample project with the option * name to be created in the current directory.
  • *
  • --help - prints help to stdout
  • *
  • [no options] - arguments are assumed to be commands that are * dispatched to a new project
  • *
* * @param args * not used */ public static void main(String[] args) { new ProtoExecutableMain(args); } private ArgumentAcceptingOptionSpec sampleOption; private OptionSpecBuilder helpOption; private OptionParser parser; private OptionSet options; private String[] args; public ProtoExecutableMain(String[] args) { this.args = args; this.parser = new OptionParser(); String createDescription = String .format( "specify the name of a sample project to create, can be one of: %s, %s, %s, %s, %s or %s", "acme", "ajc", "alien", "basic", "helloworld", "serverdemo"); this.sampleOption = parser.accepts("sample", createDescription) .withRequiredArg(); sampleOption.describedAs("project name"); this.helpOption = parser.acceptsAll(Arrays.asList("help", "?"), "show help"); this.options = parser.parse(args); if (options.has(helpOption)) { parser.printHelpOn(System.out); } else if (options.has(sampleOption)) { createSampleProject(options.valueOf(sampleOption)); } else { dispatchCommands(); } } private void dispatchCommands() { StandardProject standardProject = new StandardProject(args, null); standardProject.getDispatchFeature().dispatchCommands(); } private void createSampleProject(String projectName) { ProtoProject project = new ProtoProject(new File("."), "unspecified", null); SampleProjectFeature feature = project.getSampleProjectFeature(); if (projectName.equals("basic")) { feature.createBasicProject(new File(".")); } else if (projectName.equals("acme")) { feature.createAcmeProject(new File(".")); } else if (projectName.equals("ajc")) { feature.createAjcProject(new File(".")); } else if (projectName.equals("alien")) { feature.createAlienProject(new File(".")); } else if (projectName.equals("helloworld")) { feature.createHelloWorldProject(new File(".")); } else if (projectName.equals("serverdemo")) { feature.createServerDemoProject(new File(".")); } else { System.out.println("unrecognized project name: " + projectName); parser.printHelpOn(System.out); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy