com.clothcat.sysutils.info.Arch.java Source code

Java tutorial

Introduction

Here is the source code for com.clothcat.sysutils.info.Arch.java

Source

/*
 * The MIT License
 *
 * Copyright 2014 Stephen Stafford.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.clothcat.sysutils.info;

import com.clothcat.sysutils.Constants;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/**
 *
 * @author Stephen Stafford <clothcat@gmail.com>
 */
public class Arch {

    static final String version = "Arch version 0.0\n" + "Copyright \u00A9 2014 " + Constants.SSTA_NAME + "  "
            + Constants.SSTA_EMAIL + "\n" + "License:" + Constants.MIT_LICENSE;

    public static void main(String[] args) {
        arch(args);
    }

    public static void arch(String[] args) {
        // parse commandline
        Options options = new Options();
        options.addOption("h", "help", false, "display help output and exit");
        options.addOption("v", "version", false, "output version information and exit");

        CommandLineParser parser = new GnuParser();
        try {
            CommandLine cmd = parser.parse(options, args);
            if (cmd.hasOption("help")) {
                HelpFormatter formatter = new HelpFormatter();
                formatter.printHelp("Arch [options]", options);
                return;
            }
            if (cmd.hasOption("version")) {
                System.out.println(version);
                return;
            }
        } catch (ParseException ex) {
            Logger.getLogger(Arch.class.getName()).log(Level.SEVERE, null, ex);
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Arch [options]", options);
        }
        System.out.println(System.getProperties().getProperty("os.arch"));
    }
}