App-FileSync
view release on metacpan or search on metacpan
lib/App/FileSync/CLI.pm view on Meta::CPAN
use App::FileSync::Admin;
use App::FileSync::Args qw(with_options);
use App::FileSync::Client;
use App::FileSync::Config;
use App::FileSync::Constants qw(
$EXIT_OK $EXIT_FATAL $EXIT_LOCKED $EXIT_WARNINGS $EXIT_DRIFT $EXIT_MAX
$DEFAULT_SERVER_ROOT $PROTOCOL_VERSION $ROLE_CLIENT @ROLES $ROOT_MARKER $MAX_ID_LENGTH $TYPE_FILE
$TRASH_DAYS $MAX_DELETES $MAX_DELETE_PERCENT
);
use App::FileSync::I18N qw(message throw strip_location);
use App::FileSync::IO qw(ensure_dir);
use App::FileSync::Protocol;
use App::FileSync::Server;
use App::FileSync::Settings;
use App::FileSync::Transport::SSH;
use version; our $VERSION = version->declare('0.002.2');
# What the marker file says to anyone who finds it. File content, not a
# message: it must not change with the reader's language.
Readonly::Scalar my $MARKER_TEXT => "This directory is a filesync root; do not delete this file.\n";
# The client's default local-trash retention, written by init.
Readonly::Scalar my $LOCAL_TRASH_DAYS => 30;
# How many journal events "filesync-admin log" shows by default.
Readonly::Scalar my $ADMIN_LOG_LIMIT => 20;
# Size units for human-readable byte counts.
Readonly::Scalar my $KIB => 1024;
Readonly my @SIZE_UNITS => ([ $KIB ** 3, 'GB' ], [ $KIB ** 2, 'MB' ], [ $KIB, 'kB' ]);
# The client commands and their handlers.
Readonly my %CLIENT_COMMANDS => (
help => '_client_help',
'--help' => '_client_help',
version => '_client_version',
init => '_client_init',
sync => '_client_sync',
status => '_client_status',
log => '_client_log',
settings => '_client_settings',
verify => '_client_verify',
restore => '_client_restore',
snapshot => '_client_snapshot',
);
# The admin commands; a hashref value is a group of sub-commands.
Readonly my %ADMIN_COMMANDS => (
repo => { create => '_admin_repo_create', list => '_admin_repo_list', show => '_admin_repo_show' },
client => { allow => '_admin_client_allow', list => '_admin_client_list', forget => '_admin_client_forget' },
log => '_admin_log',
verify => '_admin_verify',
reindex => '_admin_reindex',
restore => '_admin_restore',
);
# Settings whose empty value means "the transport's default", and what to
# show instead of a blank column.
Readonly my %BLANK_SETTING => (
log_file => 'cli.settings.stderr',
ssh_identity => 'cli.settings.ssh_default',
ssh_known_hosts => 'cli.settings.ssh_default',
server_command => 'cli.settings.server_default',
);
# Journal fields "filesync-admin log" prints as key=value, in this order.
Readonly my @EVENT_FIELDS => qw(from winner loser_name exit trash sha256);
Readonly my @EVENT_COUNTERS => qw(actions deletions conflicts pulled pushed deleted);
Readonly my %EVENT_LABEL => (loser_name => 'loser');
=encoding utf8
=head1 NAME
App::FileSync::CLI - the filesync, filesync-admin and filesync-server commands
=head1 SYNOPSIS
# bin/filesync
use App::FileSync::CLI;
exit App::FileSync::CLI::run_client(@ARGV);
=head1 DESCRIPTION
Each C<run_*> function runs one command line and returns the exit code; it
never dies. Errors are reported through the logger (or standard error if the
settings that configure the logger are themselves broken), without Perl file
and line numbers. Text output goes to standard output; C<--json> prints one
JSON document instead.
Client exit codes: 0 ok, 1 fatal, 2 another run holds the lock, 3 completed
with warnings, 4 verification found drift. Admin: 0, 1 and 4. Server: 0
after a session that finished, 1 after any other (a bad argument, a refused
forced command, a protocol error, or another session holding the repo lock;
the journal records a lock refusal as exit 2, but the process exits 1).
=head1 FUNCTIONS
=head2 run_client
Documented with L</run_server> below.
=head2 run_admin
Documented with L</run_server> below.
=head2 run_server
Purpose: run C<filesync>, C<filesync-admin> or C<filesync-server>.
Args: the command line, without the program name.
Returns: the exit code.
Side Effects: whatever the command does; prints to standard output and logs
to standard error. C<run_server> speaks the protocol on standard input and
output and refuses to run on a terminal unless C<FILESYNC_ALLOW_TTY> is set.
Usage:
( run in 1.464 second using v1.01-cache-2.11-cpan-60884a8df76 )