GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Strnadj/JavaOptParser: Java Option parser inspired by OptParser ruby class

BranchesTags
Open more actions menu

Latest commit

 

History

16 Commits
16 Commits

Folders and files

NameName
Last commit message
Last commit date
.settings
.settings
 
 
src
src
 
 
.classpath
.classpath
 
 
.gitignore
.gitignore
 
 
.project
.project
 
 
.travis.yml
.travis.yml
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

Java Option Parser

Build Status Coverage Status

Info

Java Simple Option parser is inspired from ruby OptParser class (rdoc/OptionParser). This work has been created as part of Semester Work on University of West Bohemia (zcu.cz).

Installation

Add java source files in to your project and import them in files in which you want to use them.

Usage

You can find usage in tests or in example bellow. JavaOpt class provides basic fluent interfaces for creating option definitions.

Difference between Option and Path/Expression

  • Option - classic option (ex: -v, --verbose)
  • Path/Expression - string or path after option fields
cd *path/expression*
cd ~/strnadj/Projects
cp *option* *path/expression* *path/expression*
cp -R ~/strnadj/Projects ~/strnadj/Projects_bacup/

Example

We want basic ls command with options:

  • Only files
  • Only directories
  • With hidden files
  • Help
  • And optional path

Create parser definition

OptParser options = OptParser.createOptionParser("ls", "Show directory
contents")
    .addOption('f', "files", OptParser.OPTIONAL, "", "Just files")
    .addOption('d', "directories", OptParser.OPTIONAL, "", "Just
directories")
    .addOption('h', "help", OptParser.OPTIONAL, "", "Show this help")
    .addPathOrExpression("path", OptParser.OPTIONAL, ".", "Directory to
listing");

Create option with required value?

.addOptionRequiredValue('t', "target", OptParser.OPTIONAL, null, "Target
folder")

Get help?

System.out.println(options.getHelp());
Usage: ls [options] "path"

Optional options:
	-f, --files         Just files
	-d, --directories   Just directories	
	-h, --help          Show this help

Parse parameters

try {
    options.parseArguments(args);
} catch(Exception e) {
    System.err.println(e.getMessage());
    System.exit(-1);
}

Getting parameters

// Get if parameter was set
if (options.getOption("help") != null) {
    // Parameter help was set
}

// Values?
if (options.getOption("directories") != null) {
    options.getOption("directories").value();
}

Licence (DWTFYWTPL)

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 1991

Copyright (C) 2014 Jan Strnadek [email protected]

Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  1. You just DO WHAT THE FUCK YOU WANT TO.

I renounce responsibility for any damage or whatever this library caused to who use it.

How to contribute?

  1. Fork it!
  2. Do your changes!
  3. Create pull-request and open issue!

Thanks Strnadj :)

About

Java Option parser inspired by OptParser ruby class

Resources

Readme
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.