App-Dochazka-CLI
view release on metacpan or search on metacpan
bin/dochazka-cli view on Meta::CPAN
#!/usr/bin/perl
# *************************************************************************
# Copyright (c) 2014-2016, SUSE LLC
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of SUSE LLC nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# *************************************************************************
#
# Dochazka CLI script
#
use 5.012;
use strict;
use warnings;
use App::CELL qw( $CELL $log $site $meta );
use App::Dochazka::CLI qw( $debug_mode $current_emp $current_priv $prompt_date );
use App::Dochazka::CLI::Completion qw( dochazka_cli_completion );
use App::Dochazka::CLI::Parser qw( process_command );
use App::Dochazka::CLI::Util qw( authenticate_to_server init_logger init_prompt );
use App::Dochazka::Common::Model::Employee;
use Data::Dumper;
use File::HomeDir;
use Getopt::Long 2.32;
use JSON;
use Pod::Usage;
use Term::ReadKey;
use Term::ReadLine;
use Web::MREST::CLI qw( init_cli_client );
my $JSON = JSON->new->pretty;
=head1 NAME
dochazka-cli - Command-line client for Dochazka Attendance & Time Tracking System
=head1 SYNOPSIS
Assuming Dochazka REST server is running on port 5000:
$ dochazka-cli http://localhost:5000
Loading configuration files from /usr/lib/perl5/site_perl/5.20.1/auto/share/dist/App-Dochazka-CLI
Authenticating to server at http://localhost:5000
Username:
Server is alive
Dochazka(2015-03-11) root ADMIN>
This is the Dochazka command-line interface (CLI). Options:
--debug -d Make parser display debug messages
--help -h Get help
--noauth -n Omit authentication
--password -p Specify password
--sitedir -s Specify sitedir
--user -u Specify username
--version -v Display App::Dochazka::CLI version number
For more information, see L<http://metacpan.org/pod/App::Dochazka::CLI>.
=head1 DESCRIPTION
This script is used to start the Dochazka command line interface, hereinafter
referred to as "the CLI".
CLI commands are documented in L<App::Dochazka::CLI::Guide>.
=cut
local $Data::Dumper::Terse = 1;
$log->init(
ident => "DochazkaCLI",
debug_mode => 1,
);
my $server = '';
my $home = File::HomeDir->my_home;
my $noauth = 0;
my $versionparam = 0;
sub get_prompt {
init_prompt();
if ( $noauth ) {
return "App::Dochazka::CLI> ";
} else {
return "Dochazka($prompt_date) " . $current_emp->nick . " " . uc $current_priv . "> ";
}
}
sub printversion {
print "App::Dochazka::CLI version $App::Dochazka::CLI::VERSION\n";
exit(0);
}
# -------------------------------------------------------------------------
# main
# -------------------------------------------------------------------------
# process command-line options
my $help = 0;
my $user = '';
my $password = '';
my $sitedir;
my $early_debug;
GetOptions(
'help|?' => \$help,
'user|u=s' => \$user,
'password|p=s' => \$password,
'sitedir|s=s' => \$sitedir,
'noauth|n' => \$noauth,
'debug|d' => \$debug_mode,
'early-debug|e=s' => \$early_debug,
'version|v' => \$versionparam,
);
pod2usage(1) if $help;
print "Debug mode: parser state dumps will be generated\n" if $debug_mode;
printversion() if $versionparam;
# assemble array of sitedirs
if ( $sitedir and not -d $sitedir ) {
die "sitedir value must be a valid directory";
}
my @sitedirs;
foreach my $target ( '/etc/dochazka-cli', "$home/.dochazka-cli", $sitedir ) {
if ( defined( $target ) and -d $target ) {
( run in 0.674 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )