Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created October 15, 2010 02:25
Show Gist options
  • Save xaicron/627490 to your computer and use it in GitHub Desktop.
Save xaicron/627490 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/jperl
use strict;
use warnings;
use Getopt::Compact::WithCmd;
use Data::Dumper;
my $go = Getopt::Compact::WithCmd->new(
modes => [qw/verbose/],
global_struct => [
[ [qw/o output/], 'output filename', '=s', undef, { required => 1 } ],
],
command_struct => {
foo => {
options => [
[ [qw/d define/], 'define variables', '=s%', undef, { required => 1 } ],
],
desc => 'this is foo',
},
},
);
my $opt = $go->opts;
my $cmd = $go->command || '';;
print "opt: ", Dumper $opt;
print "command: $cmd\n";
print "\@ARGV: ", Dumper \@ARGV;
__END__
#!/usr/local/bin/jperl
use strict;
use warnings;
use Getopt::Compact::WithCmd;
use Data::Dumper;
my $go = Getopt::Compact::WithCmd->new(
modes => [qw/verbose/],
global_struct => [
[ [qw/o output/], 'output filename', '=s', undef, { required => 1 } ],
],
);
my $opt = $go->opts;
print "opt: ", Dumper $opt;
print "\@ARGV: ", Dumper \@ARGV;
__END__
#!/usr/local/bin/jperl
use strict;
use warnings;
use Getopt::Compact::WithCmd;
use Data::Dumper;
my $go = Getopt::Compact::WithCmd->new(
global_struct => [
[ [qw/v verbose/], 'verbose mode' ],
],
command_struct => {
foo => {
options => [
[ [qw/d define/], 'define variables', '=s%', undef, { default => { hoge => 'fuga' } } ],
],
desc => 'this is foo',
command_struct => {
bar => {
options => [
[ [qw/f force/], 'force overwrite' ],
],
desc => 'bar',
},
},
},
hoge => {
desc => 'Hoge Hoge',
},
},
);
my $opt = $go->opts;
my $cmd = $go->command || '';
my $cmds = $go->commands;
print "opt: ", Dumper $opt;
print "command: $cmd\n";
print "commands: ", Dumper $cmds;
print "\@ARGV: ", Dumper \@ARGV;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment