Git Product home page Git Product logo

getopt-kinoko's Introduction

Getopt-Kinoko

A command line parsing tool which written in Perl6 .

Getopt::Kinoko is a powerful command line parsing module, support function style interface getopt> can handle a single OptionSet and OO style interface which can handle multi OptionSet at same time(just as overload the MAIN routine). OptionSet is a class used to describe a set of Option, It support group the Options together with Group::Normal Group::Radio Group::Multi Group, and you can also set a NonOption::Front NonOption::All NonOption handle user input non-option parameters. The option of OptionSet can be one kind of Option::String Option::Integer Option::Boolean etc. They use a simple string such as "h|help=b;" describe basic configuration, and you can through OptionSet's interface set their default value and callback funtion.

Getopt::Kinoko是一个强大的命令行解析模块,支持使用函数式接口处理单个OptionSet以及面向对象接口处理多个OptionSet(就如同重载的MAIN函数),OptionSet是用来描述一组选项的类,OptionSet支持以normal(普通选项)、radio(单一选项)、multi(多选选项)等方式把选项组合在一起,并且还可以设置OptionSet的front(第一个非选项参数处理设施)、all(所有非选项参数处理设施)处理用户输入的非选项参数。Getopt::Kinoko,OptionSet中的选项可以是string(字符串)、integer(整数)、boolean(布尔)等选项中的一种,选项使用字符串来描述基本配置,你可以通过OptionSet的接口设置它们的默认值以及当选项被用户设置时的回调函数。

Usage

Find file example

#!/usr/bin/env perl6

use Getopt::Kinoko;

my OptionSet $opts .= new();

$opts.insert-normal("h|help=b;v|version=b;");
$opts.insert-multi("w=b;");
$opts.insert-radio("d|directory=b;f|file=b;l|link=b;", :force);
$opts.push-option(
  "size-limit=i",
  callback => -> \value {
    die "Invalid integer value."
      if value !~~ Int;
  }
);
&main(getopt($opts, :gnu-style));

sub main(@noa) {
  die "Not support multi keyword"
    if +@noa > 2;

  die "Need more arguments"
    if +@noa < 2;

  note "Version 0.0.1"
    if $opts{'v'};

  if $opts{'h'} || $opts{'v'} {
    note "{$*PROGRAM-NAME} " ~ $opts.usage; exit 0; 
  }

  my ($dir, $key) = @noa;

  die "Invalid directory {$dir}"
    if $dir.IO !~~ :d;

  search($opts, $dir, $key, -> $file { say $file.path(); });
}

sub search(OptionSet $opts, Str $dir, Str $key, &callback) {
  for $dir.IO.dir(:all) -> $file {
    my $name = $file.basename;

    next if $opts{'w'} && $name ne $key;
    next if $opts{'d'} && !$file.d;
    next if $opts{'f'} && (!$file.f || $file.s < $opts{'size-limit'}.Int);
    next if $opts{'l'} && !$file.l;

    &callback($file);
  }
}

更多样例请参考sample。

Installation

  • install with panda

    panda install Getopt::Kinoko

  • install with zef

    zef install Getopt::Kinoko

    If zef install Getopt::Kinoko not working, please run zef update first.

  • install

    git clone https://github.com/araraloren/Getopt-Kinoko.git

    cd Getopt-Kinoko && zef install .

getopt-kinoko's People

Contributors

araraloren avatar

Watchers

James Cloos avatar Paul Cochrane avatar  avatar

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.