NAME

LEOCHARRE::CLI - useful subs for coding cli scripts

DESCRIPTION

I use this module as base for my CLI scripts. It standardizes some things

CLI options:

-d is always debug
-h is always print help and exit
-v is always print version and exit

SUBS

config()

argument is abs paht to YAML conf file returns conf hash warns and returns undef if file is not there

yn()

prompt user for y/n confirmation will loop until it returs true or false argument is the question for the user

yn('are you sure you want to X?') or exit;

_scriptname()

returns name of script, just the name.

DEBUG

returns boolean if script has -d flag, this is on.

USER TYPE SUBS

force_root()

will force program to exit if user if whoami is not root.

running_as_root()

returns boolean

whoami()

returns who you are running as, name if which('whoami') does not return, returns undef

CLI PARAMETERS AND OPTIONS

PATH ARGUMENTS

argv_aspaths()

returns array ref of argument variables treated as paths, they are resolved with Cwd::abs_path() Any arguments that do not resolve, are skipped with a warning. if no abs paths are present after checking, returns undef files are checked for existence returns undef if no @ARGVS or none of the args are on disk skips over files not on disk with warnings

argv_aspaths_strict()

Same as argv_aspaths(), but returns false if any of the file arguments are no longer on disk

argv_aspaths_loose()

Same as argv_aspaths(), but does not check for existence, only resolved to abs paths

man()

will print manual and exit.

mktmpdir()

will make a temp dir in /tmp/tmp_$rand returns abs path to dir returns undef and warns if it cant will not overrite an existing dir, returns undef if already exists (unlikely).

CLI OPTIONS AND PARAMETERS

gopts()

returns hash of options uses Getopt::Std, forces v for version, h for help d for debug

To get standard with v and h:

my $o = gopts(); 

To add options

my $o = gopts('af:');

Adds a (bool) and f(value), v and h are still enforced.

OTHER IMPORTED SUBS

File::Which 'which' Cwd

AUTHOR

Leo Charre leocharre at cpan dot org

LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself, i.e., under the terms of the "Artistic License" or the "GNU General Public License".

COPYRIGHT

Copyright (c) 2007 Leo Charre. All rights reserved.