Giter VIP home page Giter VIP logo

getopt-mini's Introduction

NAME

Getopt::Mini

VERSION

version 0.01

SYNOPSIS

use Getopt::Mini;
say $ARGV{'flag'};

DESCRIPTION

This is, yup, yet another Getopt module, a very lightweight one. It's not declarative in any way, ie, it does not support specs, like Getopt::Long et al do.

On the other hand, it can validate your parameters using the Data::Validator syntax. But that's a hidden feature for now (you'll need to install Data::Validator yourself and find a way to run it by reading this source code).

NAME

Getopt::Mini - yet another yet-another Getopt module

VERSION

version 0.01

USAGE

The rules:

* -<char>              
    does not consume barewords (ie. -f, -h, ...)

* -<str> <bareword>
* --<str> <bareword>  
    will eat up the next bare word (-type f, --file f.txt)

* -<char|str>=<val> and --<str>=<val> 
    consumes its value and nothing more 

* <str>
    gets pushed into an array in $ARGV{''}

Some code examples:

perl myprog.pl -h -file foo --file bar
use Getopt::Mini;   # parses the @ARGV into %ARGV
say YAML::Dump \%ARGV;
---
h: 1
file: 
  - foo
  - bar

# single flags like -h are checked with exists:

say 'help...' if exists $ARGV{'h'};

# barewords are pushed into the key '_'

perl myprog.pl file1.c file2.c 
say "file: $_" for @{ $ARGV{''} };

Or you can just use a modular version:

use Getopt::Mini later=>1; # nothing happens

getopt;   #  imports into %ARGV
my %argv = getopt;   #  imports into %argv instead

array mode

There's also a special mode that can be set with array = 1> that will make a flag consume all following barewords:

perl myprog.pl -a -b --files f1.txt f2.txt
use Getopt::Mini array => 1; 
say YAML::Dump \%ARGV;
---
h: ~
file: 
  - foo
  - bar

BUGS

This is *ALPHA* software. And despite its small footprint, this is lurking with nasty bugs and potential api changes.

Complaints should be filed to the Getopt Foundation, which has been treating severe NIH syndrome since 1980.

SEE ALSO

Getopt::Whatever - no declarative spec like this module, but the options in %ARGV and @ARGV are not where I expect them to be.

Getopt::Casual - similar to this module, but very keen on turning entries into single param options.

AUTHOR

Rodrigo de Oliveira <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Rodrigo de Oliveira.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.