Getopt-Long-Subcommand

 view release on metacpan or  search on metacpan

t/01-basic.t  view on Meta::CPAN

#!perl

use 5.010001;
use strict;
use warnings;
use Test::More 0.98;

use Getopt::Long::Subcommand;

subtest "basics" => sub {
    local @ARGV;
    my @output;

    my @spec = (
        summary => 'Program summary',
        options => {
            'help|h|?' => {
                summary => 'Display help',
                handler => sub { push @output, 'General help message' },
            },
            'version|v' => {
                summary => 'Display version',
                handler => sub { push @output, 'Version 1.0' },
            },
        },
        subcommands => {
            sc1 => {
                summary => 'Subcommand1 summary',
                options => {
                    'opt1=s' => {
                        handler => sub { push @output, "set sc1.opt1=$_[1]" },
                    },
                    'opt2=s' => {
                        handler => sub { push @output, "set sc1.opt2=$_[1]" },
                    },
                },
            },
            sc2 => {
                summary => 'Subcommand2 summary',
                options => {
                    'help|h|?' => {
                        summary => 'Display subcommand2 help',
                        handler => sub { push @output, 'Sc2 help message' },
                    },
                    'opt1=i' => {
                        handler => sub { push @output, "set sc2.opt1=$_[1]" },
                    },
                },
                subcommands => {
                    sc21 => {
                        subcommands => {
                            sc211 => {
                                subcommands => {
                                    sc2111 => {},
                                },
                            },
                        },
                    },
                },
            },
            # to test cmdspec key 'configure'
            sc3 => {
                summary => 'Subcommand3 summary',
                configure => ['ignore_case'],
                options => {
                    'Opt1|A=s' => {
                        handler => sub { push @output, "set sc3.Opt1=$_[1]" },
                    },
                    'Opt2|B=s' => {
                        handler => sub { push @output, "set sc3.Opt2=$_[1]" },
                    },



( run in 0.691 second using v1.01-cache-2.11-cpan-a9496e3eb41 )