App-Sky
view release on metacpan or search on metacpan
lib/App/Sky/CmdLine.pm view on Meta::CPAN
package App::Sky::CmdLine;
$App::Sky::CmdLine::VERSION = '0.8.0';
use strict;
use warnings;
use 5.020;
use utf8;
use Carp ();
use Moo;
use MooX 'late';
use Getopt::Long qw(GetOptionsFromArray);
use App::Sky::Config::Validate ();
use App::Sky::Manager ();
use File::HomeDir ();
use YAML::XS qw(LoadFile);
use Scalar::Util qw(reftype);
has 'argv' => ( isa => 'ArrayRef[Str]', is => 'rw', required => 1, );
# Better than DATA , IMHO
my $INIT_YAML_CONFIG_CONTENTS = <<"ENDFILE";
---
default_site: homepage
sites:
homepage:
base_upload_cmd:
- 'rsync'
- '-a'
- '-v'
- '--progress'
- '--inplace'
dest_upload_prefix: 'hostgator:public_html/'
dest_upload_url_prefix: 'https://www.destsite.tld/'
dirs_section: 'dirs'
sections:
archives:
basename_re: '\\.(?:7z|AppImage\\.xz|ova(?:\\.xz)?|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tar\\.zst|zip|exe|rpm)(?:\\.zsync)?\\z'
target_dir: 'Files/files/arcs/'
code:
basename_re: '\\.(?:bash|c|cpp|diff|hs|js|json|log|p6|patch|pl|pm|py|rb|rs|s|scm|spec|ts|vim|yaml|yml)(?:\\.bz2|\\.gz|\\.xz\\|\\.zst)?\\z'
target_dir: 'Files/files/code/'
dirs:
basename_re: '\\.(MYDIR)\\z'
target_dir: 'Files/files/dirs/'
images:
basename_re: '\\.(?:bmp|gif|jpeg|jpg|kra|png|(?:ai|svg|xcf)(?:\\.bz2|\\.gz|\\.xz\\|\\.zst)?|svgz|webp)\\z'
target_dir: 'Files/files/images/'
music:
basename_re: '\\.(?:aac|aup3|m4a|mod|mp3|ogg|s3m|wav|xm)\\z'
target_dir: 'Files/files/music/mp3-ogg/'
text:
basename_re: '\\.(?:asciidoc|docx|epub|html|md|mkdn|ods|odt|pdf|tsv|txt|xml|xhtml|xlsx)(?:\\.bz2|\\.gz|\\.xz\\|\\.zst)?\\z'
target_dir: 'Files/files/text/'
video:
basename_re: '\\.(?:avi|flv|mkv|mp4|mpeg|mpg|ogv|srt|webm)\\z'
target_dir: 'Files/files/video/'
ENDFILE
sub _basic_help
{
my ($self) = @_;
print <<'EOF';
sky upload /path/to/myfile.txt
sky up-r /path/to/directory
Specifying --copy or -x will copy the URL to the clipboard.
EOF
exit(0);
}
sub _basic_usage
{
my ($self) = @_;
print "Usage: sky [up|upload] /path/to/myfile.txt\n";
exit(-1);
}
sub _is_copy_to_clipboard
{
my ( $self, $flag ) = @_;
return ( $flag =~ /\A(--copy|-x)\z/ );
}
sub _shift
{
my $self = shift;
return shift( @{ $self->argv() } );
}
sub _write_utf8_file
{
my ( $out_path, $contents ) = @_;
open my $out_fh, '>:encoding(utf8)', $out_path
or die "Cannot open '$out_path' for writing - $!";
print {$out_fh} $contents;
close($out_fh);
( run in 0.552 second using v1.01-cache-2.11-cpan-df04353d9ac )