#!perl

### code_after_shebang
# Note: This script is a CLI 
# and generated automatically using Perinci::CmdLine::Gen version 0.46

# PERICMD_INLINE_SCRIPT: {"code_after_shebang":"...","config_dirs":null,"config_filename":"reposdb-inline.conf","env_name":"REPOSDB_INLINE_OPT","include":null,"log":null,"pack_deps":"0","pod":0,"read_config":1,"read_env":1,"script_name":"reposdb-inline","script_summary":null,"script_version":"0.005","shebang":"perl","skip_format":0,"subcommands":{"ls":{"url":"/App/reposdb/list_repos"},"remove-all-tags":{"url":"/App/reposdb/remove_all_repo_tags"},"remove-tag":{"url":"/App/reposdb/remove_repo_tag"},"touch":{"url":"/App/reposdb/touch_repo"}},"url":"/App/reposdb/","use_cleanser":1,"validate_args":1}

my $_pci_metas = do{my$a={ls=>{args=>{detail=>{cmdline_aliases=>{l=>{}},schema=>["bool",{},{}],tags=>["category:field-selection"]},has_tags=>{element_completion=>sub{"DUMMY"},schema=>["array",{of=>["str",{req=>1},{}],req=>1},{}],tags=>["category:filtering"],"x.name.is_plural"=>1,"x.name.singular"=>"has_tag"},lacks_tags=>{element_completion=>'fix',schema=>["array",{of=>["str",{req=>1},{}],req=>1},{}],tags=>["category:filtering"],"x.name.is_plural"=>1,"x.name.singular"=>"lacks_tag"},reposdb_path=>{req=>1,schema=>["str",{req=>1},{}],tags=>["common"]},sorts=>{default=>["name"],schema=>["array",{of=>["str",{in=>["name","-name","commit_time","-commit_time","status_time","-status_time","pull_time","-pull_time"],req=>1},{}],req=>1},{}],tags=>["category:sorting"],"x.name.is_plural"=>1}},result=>{},summary=>"List repositories registered in repos.db",v=>1.1},"remove-all-tags"=>{args=>{repo=>{completion=>sub{"DUMMY"},pos=>0,schema=>["str",{req=>1},{}]},reposdb_path=>{req=>1,schema=>["str",{req=>1},{}],tags=>'fix'}},result=>{},v=>1.1},"remove-tag"=>{args=>{repo=>{completion=>'fix',pos=>0,schema=>["str",{req=>1},{}]},reposdb_path=>{req=>1,schema=>["str",{req=>1},{}],tags=>'fix'},tags=>{element_completion=>'fix',greedy=>1,pos=>1,req=>1,schema=>["array",{of=>["str",{req=>1},{}],req=>1},{}],"x.name.is_plural"=>1}},result=>{},v=>1.1},touch=>{args=>{commit_time=>{schema=>["bool",{is=>1},{}]},pull_time=>{schema=>["bool",{is=>1},{}]},repo=>{completion=>'fix',pos=>0,schema=>["str",{req=>1},{}]},reposdb_path=>{req=>1,schema=>["str",{req=>1},{}],tags=>'fix'},status_time=>{schema=>["bool",{is=>1},{}]},to=>{schema=>["date",{req=>1},{}]}},args_rels=>{req_some=>[1,3,["commit_time","status_time","pull_time"]]},result=>{},v=>1.1}};$a->{ls}{args}{lacks_tags}{element_completion}=$a->{ls}{args}{has_tags}{element_completion};$a->{"remove-all-tags"}{args}{reposdb_path}{tags}=$a->{ls}{args}{reposdb_path}{tags};$a->{"remove-tag"}{args}{repo}{completion}=$a->{"remove-all-tags"}{args}{repo}{completion};$a->{"remove-tag"}{args}{reposdb_path}{tags}=$a->{ls}{args}{reposdb_path}{tags};$a->{"remove-tag"}{args}{tags}{element_completion}=$a->{ls}{args}{has_tags}{element_completion};$a->{touch}{args}{repo}{completion}=$a->{"remove-all-tags"}{args}{repo}{completion};$a->{touch}{args}{reposdb_path}{tags}=$a->{ls}{args}{reposdb_path}{tags};$a};

# This script is generated by Perinci::CmdLine::Inline version 0.53 on Mon Jul 10 18:36:25 2017.

# Rinci metadata taken from these modules: App::reposdb (no version)

# You probably should not manually edit this file.

our $DATE = '2017-07-10'; # DATE
our $VERSION = '0.005'; # VERSION
# PODNAME: reposdb-inline

package main;
use 5.010001;
use strict;
#use warnings;

### declare global variables

our $_pci_meta_result_stream = 0;
our $_pci_meta_result_type;
our $_pci_meta_result_type_is_simple;
our $_pci_meta_skip_format = 0;
our $_pci_r = {naked_res=>0,read_config=>1,read_env=>1,subcommand_name=>""};
our %_pci_args;

### declare subroutines

sub _pci_err {
    my $res = shift;
    print STDERR "ERROR $res->[0]: $res->[1]\n";
    exit $res->[0]-300;
}

sub _pci_json {
    state $json = do {
        if (eval { require JSON::XS; 1 }) { JSON::XS->new->canonical(1)->allow_nonref }
        else { require JSON::PP; JSON::PP->new->canonical(1)->allow_nonref }
    };
    $json;
}

### get arguments (from config file, env, command-line args

{
my %mentioned_args;
require Getopt::Long::EvenLess;
require Getopt::Long::Subcommand;
my $help_msg = "reposdb-inline\nUsage:\n  reposdb-inline --help (or -h, -?)\n  reposdb-inline --subcommands\n  reposdb-inline --version (or -v)\n  reposdb-inline [options]\n\nSubcommands:\n  ls\n  remove-all-tags\n  remove-tag\n  touch\n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nOther options:\n  --cmd=s                        Select subcommand\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --subcommands                  List available subcommands\n  --version, -v                  Display program's version and exit\n";
my $go_spec1 = {
  'cmd=s' => sub { $_[2]{subcommand} = [$_[1]]; $_pci_r->{subcommand_name} = $_[1]; },
  'config-path=s@' => sub { $_pci_r->{config_paths} //= []; push @{ $_pci_r->{config_paths} }, $_[1]; },
  'config-profile=s' => sub { $_pci_r->{config_profile} = $_[1]; },
  'format=s' => sub { $_pci_r->{format} = $_[1]; },
  'help|h|?' => sub { my $sc_name = $_pci_r->{subcommand_name}; my $first_non_opt_arg; for (@ARGV) { next if /^-/; $first_non_opt_arg = $_; last } if (!length $sc_name && defined $first_non_opt_arg) { $sc_name = $first_non_opt_arg } if (!length $sc_name) { print $help_msg } elsif ($sc_name eq "") { print "reposdb-inline\nUsage:\n  reposdb-inline --help (or -h, -?)\n  reposdb-inline --subcommands\n  reposdb-inline --version (or -v)\n  reposdb-inline [options]\n\nSubcommands:\n  ls\n  remove-all-tags\n  remove-tag\n  touch\n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nOther options:\n  --cmd=s                        Select subcommand\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --subcommands                  List available subcommands\n  --version, -v                  Display program's version and exit\n" } elsif ($sc_name eq "ls") { print "reposdb-inline ls - List repositories registered in repos.db\n\nUsage:\n  reposdb-inline ls --help (or -h, -?)\n  reposdb-inline ls --version (or -v)\n  reposdb-inline ls [options]\n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nField selection options:\n  --detail, -l  \n\nFiltering options:\n  --has-tag=s\@    \n  --lacks-tag=s\@  \n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nSorting options:\n  --sort=s\@   [[\"name\"]]\n\nOther options:\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --reposdb-path=s*              \n  --version, -v                  Display program's version and exit\n" } elsif ($sc_name eq "remove-all-tags") { print "reposdb-inline remove-all-tags\nUsage:\n  reposdb-inline remove-all-tags --help (or -h, -?)\n  reposdb-inline remove-all-tags --version (or -v)\n  reposdb-inline remove-all-tags [options] [repo]\n\nMain options:\n  --repo=s   (=arg[0])\n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nOther options:\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --reposdb-path=s*              \n  --version, -v                  Display program's version and exit\n" } elsif ($sc_name eq "remove-tag") { print "reposdb-inline remove-tag\nUsage:\n  reposdb-inline remove-tag --help (or -h, -?)\n  reposdb-inline remove-tag --version (or -v)\n  reposdb-inline remove-tag [options] [repo] <tags> ...\n\nMain options:\n  --repo=s    (=arg[0])\n  --tag=s\@*   (=arg[1-])\n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nOther options:\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --reposdb-path=s*              \n  --version, -v                  Display program's version and exit\n" } elsif ($sc_name eq "touch") { print "reposdb-inline touch\nUsage:\n  reposdb-inline touch --help (or -h, -?)\n  reposdb-inline touch --version (or -v)\n  reposdb-inline touch [options] [repo]\n\nMain options:\n  --commit-time  \n  --pull-time    \n  --repo=s        (=arg[0])\n  --status-time  \n  --to=s         \n\nConfiguration options:\n  --config-path=filename  Set path to configuration file\n  --config-profile=s      Set configuration profile to use\n  --no-config             Do not use any configuration file\n\nEnvironment options:\n  --no-env  Do not read environment for default options\n\nOutput options:\n  --format=s  Choose output format, e.g. json, text\n  --json      Set output format to json\n\nOther options:\n  --help, -h, -?                 Display help message and exit\n  --naked-res                    When outputing as JSON, strip result envelope\n  --no-naked-res, --nonaked-res  When outputing as JSON, don't strip result envelope\n  --reposdb-path=s*              \n  --version, -v                  Display program's version and exit\n" } else { _pci_err([500, "Unknown subcommand2: $sc_name"]) } exit 0 },
  'json' => sub { $_pci_r->{format} = (-t STDOUT) ? "json-pretty" : "json"; },
  'naked-res' => sub { $_pci_r->{naked_res} = 1; },
  'no-config' => sub { $_pci_r->{read_config} = 0; },
  'no-env' => sub { $_pci_r->{read_env} = 0; },
  'no-naked-res|nonaked-res' => sub { $_pci_r->{naked_res} = 0; },
  'subcommands' => sub { print "Available subcommands:\n  ls\n  remove-all-tags\n  remove-tag\n  touch\n"; exit 0 },
  'version|v' => sub { no warnings 'once'; require App::reposdb; print "reposdb-inline version ", "0.005", ($App::reposdb::DATE ? " ($App::reposdb::DATE)" : ''), "\n"; print "  Generated by Perinci::CmdLine::Inline version 0.53 (2017-07-04)\n"; exit 0 },
};
my $go_spec2 = {
  options => {
    'cmd=s' => {
      handler => sub { $_[2]{subcommand} = [$_[1]]; $_pci_r->{subcommand_name} = $_[1]; },
    },
    'config-path=s@' => {
      handler => sub {},
    },
    'config-profile=s' => {
      handler => sub {},
    },
    'format=s' => {
      handler => sub {},
    },
    'help|h|?' => {
      handler => sub {},
    },
    'json' => {
      handler => sub {},
    },
    'naked-res' => {
      handler => sub {},
    },
    'no-config' => {
      handler => sub {},
    },
    'no-env' => {
      handler => sub {},
    },
    'no-naked-res|nonaked-res' => {
      handler => sub {},
    },
    'subcommands' => {
      handler => sub {},
    },
    'version|v' => {
      handler => sub {},
    },
  },
  subcommands => {
    'ls' => {
      options => {
        'detail' => {
          handler => sub { $_pci_args{'detail'} = $_[1]; },
        },
        'has-tag=s@' => {
          handler => sub { if ($mentioned_args{'has_tags'}++) { push @{ $_pci_args{'has_tags'} }, $_[1] } else { $_pci_args{'has_tags'} = [$_[1]] } },
        },
        'has-tags-json=s' => {
          handler => sub { $_pci_args{'has_tags'} = _pci_json()->decode($_[1]); },
        },
        'l' => {
          handler => sub { $_pci_args{'detail'} = $_[1]; },
        },
        'lacks-tag=s@' => {
          handler => sub { if ($mentioned_args{'lacks_tags'}++) { push @{ $_pci_args{'lacks_tags'} }, $_[1] } else { $_pci_args{'lacks_tags'} = [$_[1]] } },
        },
        'lacks-tags-json=s' => {
          handler => sub { $_pci_args{'lacks_tags'} = _pci_json()->decode($_[1]); },
        },
        'no-detail' => {
          handler => sub { $_pci_args{'detail'} = 0; },
        },
        'nodetail' => {
          handler => sub { $_pci_args{'detail'} = 0; },
        },
        'reposdb-path=s' => {
          handler => sub { $_pci_args{'reposdb_path'} = $_[1]; },
        },
        'sort=s@' => {
          handler => sub { if ($mentioned_args{'sorts'}++) { push @{ $_pci_args{'sorts'} }, $_[1] } else { $_pci_args{'sorts'} = [$_[1]] } },
        },
        'sorts-json=s' => {
          handler => sub { $_pci_args{'sorts'} = _pci_json()->decode($_[1]); },
        },
      },
    },
    'remove-all-tags' => {
      options => {
        'repo=s' => {
          handler => sub { $_pci_args{'repo'} = $_[1]; },
        },
        'reposdb-path=s' => {
          handler => sub { $_pci_args{'reposdb_path'} = $_[1]; },
        },
      },
    },
    'remove-tag' => {
      options => {
        'repo=s' => {
          handler => sub { $_pci_args{'repo'} = $_[1]; },
        },
        'reposdb-path=s' => {
          handler => sub { $_pci_args{'reposdb_path'} = $_[1]; },
        },
        'tag=s@' => {
          handler => sub { if ($mentioned_args{'tags'}++) { push @{ $_pci_args{'tags'} }, $_[1] } else { $_pci_args{'tags'} = [$_[1]] } },
        },
        'tags-json=s' => {
          handler => sub { $_pci_args{'tags'} = _pci_json()->decode($_[1]); },
        },
      },
    },
    'touch' => {
      options => {
        'commit-time' => {
          handler => sub { $_pci_args{'commit_time'} = $_[1]; },
        },
        'pull-time' => {
          handler => sub { $_pci_args{'pull_time'} = $_[1]; },
        },
        'repo=s' => {
          handler => sub { $_pci_args{'repo'} = $_[1]; },
        },
        'reposdb-path=s' => {
          handler => sub { $_pci_args{'reposdb_path'} = $_[1]; },
        },
        'status-time' => {
          handler => sub { $_pci_args{'status_time'} = $_[1]; },
        },
        'to=s' => {
          handler => sub { $_pci_args{'to'} = $_[1]; },
        },
      },
    },
  },
  default_subcommand => undef,
};
{
  local @ARGV = @ARGV;
  my $old_conf = Getopt::Long::EvenLess::Configure("pass_through");
  Getopt::Long::EvenLess::GetOptions(%$go_spec1);
  Getopt::Long::EvenLess::Configure($old_conf);
  { my $first_non_opt_arg; for (@ARGV) { next if /^-/; $first_non_opt_arg = $_; last } if (!length $_pci_r->{subcommand_name} && defined $first_non_opt_arg) { $_pci_r->{subcommand_name} = $first_non_opt_arg } }
}
{
  last unless $_pci_r->{read_env};
  my $env = $ENV{"REPOSDB_INLINE_OPT"};
  last unless defined $env;
  require Complete::Bash;
  my ($words, undef) = @{ Complete::Bash::parse_cmdline($env, 0) };
  unshift @ARGV, @$words;
}
if ($_pci_r->{read_config}) {
  require Perinci::CmdLine::Util::Config;

  my $res = Perinci::CmdLine::Util::Config::read_config(
    config_paths     => $_pci_r->{config_paths},
    config_filename  => "reposdb-inline.conf",
    config_dirs      => undef // ["$ENV{HOME}/.config", $ENV{HOME}, "/etc"],
    program_name     => "reposdb-inline",
  );
  _pci_err($res) unless $res->[0] == 200;
  $_pci_r->{config} = $res->[2];
  $_pci_r->{read_config_files} = $res->[3]{"func.read_files"};
  $_pci_r->{_config_section_read_order} = $res->[3]{"func.section_read_order"}; # we currently dont want to publish this request key

  $res = Perinci::CmdLine::Util::Config::get_args_from_config(
    r                  => $_pci_r,
    config             => $_pci_r->{config},
    args               => \%_pci_args,
    program_name       => "reposdb-inline",
    subcommand_name    => $_pci_r->{subcommand_name},
    config_profile     => $_pci_r->{config_profile},
    common_opts        => {},
    meta               => $_pci_metas->{ $_pci_r->{subcommand_name} },
    meta_is_normalized => 1,
  );
  die $res unless $res->[0] == 200;
  my $found = $res->[3]{"func.found"};
  if (defined($_pci_r->{config_profile}) && !$found && defined($_pci_r->{read_config_files}) && @{$_pci_r->{read_config_files}} && !$_pci_r->{ignore_missing_config_profile_section}) {
    _pci_err([412, "Profile '$_pci_r->{config_profile}' not found in configuration file"]);
  }
}
my $res = Getopt::Long::Subcommand::GetOptions(%$go_spec2);
_pci_err([500, "GetOptions failed"]) unless $res->{success};
if (!length $_pci_r->{subcommand_name}) { print $help_msg; exit 0 }
}

### check arguments

{
my $res = _pci_check_args(\%_pci_args);
_pci_err($res) if $res->[0] != 200;
$_pci_r->{args} = \%_pci_args;
}

### call function

{
my $sc_name = $_pci_r->{subcommand_name};
if ($sc_name eq "ls") {
    $_pci_meta_result_type = "";
    require App::reposdb;
    eval { $_pci_r->{res} = App::reposdb::list_repos(%_pci_args) };
    if ($@) { $_pci_r->{res} = [500, "Function died: $@"] }
}
elsif ($sc_name eq "remove-all-tags") {
    $_pci_meta_result_type = "";
    require App::reposdb;
    eval { $_pci_r->{res} = App::reposdb::remove_all_repo_tags(%_pci_args) };
    if ($@) { $_pci_r->{res} = [500, "Function died: $@"] }
}
elsif ($sc_name eq "remove-tag") {
    $_pci_meta_result_type = "";
    require App::reposdb;
    eval { $_pci_r->{res} = App::reposdb::remove_repo_tag(%_pci_args) };
    if ($@) { $_pci_r->{res} = [500, "Function died: $@"] }
}
elsif ($sc_name eq "touch") {
    $_pci_meta_result_type = "";
    require App::reposdb;
    eval { $_pci_r->{res} = App::reposdb::touch_repo(%_pci_args) };
    if ($@) { $_pci_r->{res} = [500, "Function died: $@"] }
}
}

### format & display result

{
my $fres;
my $save_res; if (exists $_pci_r->{res}[3]{"cmdline.result"}) { $save_res = $_pci_r->{res}[2]; $_pci_r->{res}[2] = $_pci_r->{res}[3]{"cmdline.result"} }
my $is_success = $_pci_r->{res}[0] =~ /\A2/ || $_pci_r->{res}[0] == 304;
my $is_stream = $_pci_r->{res}[3]{stream} // $_pci_meta_result_stream // 0;
if ($is_success && (0 || $_pci_meta_skip_format || $_pci_r->{res}[3]{"cmdline.skip_format"})) { $fres = $_pci_r->{res}[2] }
elsif ($is_success && $is_stream) {}
else { require Perinci::Result::Format::Lite; $is_stream=0; _pci_clean_json($_pci_r->{res}); $fres = Perinci::Result::Format::Lite::format($_pci_r->{res}, ($_pci_r->{format} // $_pci_r->{res}[3]{"cmdline.default_format"} // "text"), $_pci_r->{naked_res}, 0) }

my $use_utf8 = $_pci_r->{res}[3]{"x.hint.result_binary"} ? 0 : 0;
if ($use_utf8) { binmode STDOUT, ":utf8" }
if ($is_stream) {
    my $code = $_pci_r->{res}[2]; if (ref($code) ne "CODE") { die "Result is a stream but no coderef provided" } if ($_pci_meta_result_type_is_simple) { while(defined(my $l=$code->())) { print $l; print "\n" unless $_pci_meta_result_type eq "buf"; } } else { while (defined(my $rec=$code->())) { print _pci_json()->encode($rec),"\n" } }
} else {
    print $fres;
}
if (defined $save_res) { $_pci_r->{res}[2] = $save_res }
}

### exit

{
my $status = $_pci_r->{res}[0];
my $exit_code = $_pci_r->{res}[3]{"cmdline.exit_code"} // ($status =~ /200|304/ ? 0 : ($status-300));
exit($exit_code);
}

# BEGIN Local::_pci_check_args
sub _pci_check_args {
    my ($args) = @_;
    my $sc_name = $_pci_r->{subcommand_name};
    if ($sc_name eq "ls") {
      FILL_FROM_POS: {
            1;
        }
        my @check_argv = @ARGV;
        # fill from cmdline_src

        # fill defaults from "default" property and check against schema
        $args->{"sorts"} //= ["name"];

        # check required args
        return [400, "Missing required value for argument: has_tags"] if exists($args->{"has_tags"}) && !defined($args->{"has_tags"});
        return [400, "Missing required value for argument: lacks_tags"] if exists($args->{"lacks_tags"}) && !defined($args->{"lacks_tags"});
        return [400, "Missing required argument: reposdb_path"] unless exists $args->{"reposdb_path"};
        return [400, "Missing required value for argument: reposdb_path"] if exists($args->{"reposdb_path"}) && !defined($args->{"reposdb_path"});
        return [400, "Missing required value for argument: sorts"] if exists($args->{"sorts"}) && !defined($args->{"sorts"});
        _pci_err([500, "Extraneous command-line argument(s): ".join(", ", @check_argv)]) if @check_argv;
        [200];
    }    elsif ($sc_name eq "remove-all-tags") {
      FILL_FROM_POS: {
            1;
            if (@ARGV > 0) { if (exists $args->{"repo"}) { return [400, "You specified --repo but also argument #0"]; } else { $args->{"repo"} = delete($ARGV[0]); } }
        }
        my @check_argv = @ARGV;
        # fill from cmdline_src

        # fill defaults from "default" property and check against schema

        # check required args
        return [400, "Missing required value for argument: repo"] if exists($args->{"repo"}) && !defined($args->{"repo"});
        return [400, "Missing required argument: reposdb_path"] unless exists $args->{"reposdb_path"};
        return [400, "Missing required value for argument: reposdb_path"] if exists($args->{"reposdb_path"}) && !defined($args->{"reposdb_path"});
        _pci_err([500, "Extraneous command-line argument(s): ".join(", ", @check_argv)]) if @check_argv;
        [200];
    }    elsif ($sc_name eq "remove-tag") {
      FILL_FROM_POS: {
            1;
            if (@ARGV > 1) { if (exists $args->{"tags"}) { return [400, "You specified --tag but also argument #1"]; } else { $args->{"tags"} = [splice(@ARGV, 1)]; } }
            if (@ARGV > 0) { if (exists $args->{"repo"}) { return [400, "You specified --repo but also argument #0"]; } else { $args->{"repo"} = delete($ARGV[0]); } }
        }
        my @check_argv = @ARGV;
        # fill from cmdline_src

        # fill defaults from "default" property and check against schema

        # check required args
        return [400, "Missing required value for argument: repo"] if exists($args->{"repo"}) && !defined($args->{"repo"});
        return [400, "Missing required argument: reposdb_path"] unless exists $args->{"reposdb_path"};
        return [400, "Missing required value for argument: reposdb_path"] if exists($args->{"reposdb_path"}) && !defined($args->{"reposdb_path"});
        return [400, "Missing required argument: tags"] unless exists $args->{"tags"};
        return [400, "Missing required value for argument: tags"] if exists($args->{"tags"}) && !defined($args->{"tags"});
        _pci_err([500, "Extraneous command-line argument(s): ".join(", ", @check_argv)]) if @check_argv;
        [200];
    }    elsif ($sc_name eq "touch") {
      FILL_FROM_POS: {
            1;
            if (@ARGV > 0) { if (exists $args->{"repo"}) { return [400, "You specified --repo but also argument #0"]; } else { $args->{"repo"} = delete($ARGV[0]); } }
        }
        my @check_argv = @ARGV;
        # fill from cmdline_src

        # fill defaults from "default" property and check against schema

        # check required args
        return [400, "Missing required value for argument: repo"] if exists($args->{"repo"}) && !defined($args->{"repo"});
        return [400, "Missing required argument: reposdb_path"] unless exists $args->{"reposdb_path"};
        return [400, "Missing required value for argument: reposdb_path"] if exists($args->{"reposdb_path"}) && !defined($args->{"reposdb_path"});
        return [400, "Missing required value for argument: to"] if exists($args->{"to"}) && !defined($args->{"to"});
        _pci_err([500, "Extraneous command-line argument(s): ".join(", ", @check_argv)]) if @check_argv;
        [200];
    } else { _pci_err([500, "Unknown subcommand1: $sc_name"]); }
}
1;

# END Local::_pci_check_args

# BEGIN Local::_pci_clean_json
sub _pci_clean_json { require Clone::PP; require Scalar::Util;  use feature 'state'; state $cleanser = sub {
my $data = shift;
state %refs;
state $ctr_circ;
state $process_array;
state $process_hash;
if (!$process_array) { $process_array = sub { my $a = shift; for my $e (@$a) { my $ref=ref($e);
    if ($ref && $refs{ $e }++) { if (++$ctr_circ <= 1) { $e = Clone::PP::clone($e); redo } else { $e = 'CIRCULAR'; $ref = '' } }
    elsif ($ref eq 'DateTime') { $e = $e->epoch; $ref = ref($e) }
    elsif ($ref eq 'Math::BigInt') { $e = $e->bstr; $ref = ref($e) }
    elsif ($ref eq 'Regexp') { $e = "$e"; $ref = "" }
    elsif ($ref eq 'SCALAR') { $e = ${ $e }; $ref = ref($e) }
    elsif ($ref eq 'Time::Moment') { $e = $e->epoch; $ref = ref($e) }
    elsif ($ref eq 'version') { $e = "$e"; $ref = "" }
    elsif (Scalar::Util::blessed($e)) { my $reftype = Scalar::Util::reftype($e); $e = $reftype eq "HASH" ? {%{ $e }} : $reftype eq "ARRAY" ? [@{ $e }] : $reftype eq "SCALAR" ? \(my $copy = ${ $e }) : $reftype eq "CODE" ? sub { goto &{ $e } } :(die "Cannot unbless object with type $ref") }
    my $reftype=Scalar::Util::reftype($e)//"";
    if ($reftype eq "ARRAY") { $process_array->($e) }
    elsif ($reftype eq "HASH") { $process_hash->($e) }
    elsif ($ref) { $e = $ref; $ref = "" }
} } }
if (!$process_hash) { $process_hash = sub { my $h = shift; for my $k (keys %$h) { my $ref=ref($h->{$k});
    if ($ref && $refs{ $h->{$k} }++) { if (++$ctr_circ <= 1) { $h->{$k} = Clone::PP::clone($h->{$k}); redo } else { $h->{$k} = 'CIRCULAR'; $ref = '' } }
    elsif ($ref eq 'DateTime') { $h->{$k} = $h->{$k}->epoch; $ref = ref($h->{$k}) }
    elsif ($ref eq 'Math::BigInt') { $h->{$k} = $h->{$k}->bstr; $ref = ref($h->{$k}) }
    elsif ($ref eq 'Regexp') { $h->{$k} = "$h->{$k}"; $ref = "" }
    elsif ($ref eq 'SCALAR') { $h->{$k} = ${ $h->{$k} }; $ref = ref($h->{$k}) }
    elsif ($ref eq 'Time::Moment') { $h->{$k} = $h->{$k}->epoch; $ref = ref($h->{$k}) }
    elsif ($ref eq 'version') { $h->{$k} = "$h->{$k}"; $ref = "" }
    elsif (Scalar::Util::blessed($h->{$k})) { my $reftype = Scalar::Util::reftype($h->{$k}); $h->{$k} = $reftype eq "HASH" ? {%{ $h->{$k} }} : $reftype eq "ARRAY" ? [@{ $h->{$k} }] : $reftype eq "SCALAR" ? \(my $copy = ${ $h->{$k} }) : $reftype eq "CODE" ? sub { goto &{ $h->{$k} } } :(die "Cannot unbless object with type $ref") }
    my $reftype=Scalar::Util::reftype($h->{$k})//"";
    if ($reftype eq "ARRAY") { $process_array->($h->{$k}) }
    elsif ($reftype eq "HASH") { $process_hash->($h->{$k}) }
    elsif ($ref) { $h->{$k} = $ref; $ref = "" }
} } }
%refs = (); $ctr_circ=0;
for ($data) { my $ref=ref($_);
    if ($ref && $refs{ $_ }++) { if (++$ctr_circ <= 1) { $_ = Clone::PP::clone($_); redo } else { $_ = 'CIRCULAR'; $ref = '' } }
    elsif ($ref eq 'DateTime') { $_ = $_->epoch; $ref = ref($_) }
    elsif ($ref eq 'Math::BigInt') { $_ = $_->bstr; $ref = ref($_) }
    elsif ($ref eq 'Regexp') { $_ = "$_"; $ref = "" }
    elsif ($ref eq 'SCALAR') { $_ = ${ $_ }; $ref = ref($_) }
    elsif ($ref eq 'Time::Moment') { $_ = $_->epoch; $ref = ref($_) }
    elsif ($ref eq 'version') { $_ = "$_"; $ref = "" }
    elsif (Scalar::Util::blessed($_)) { my $reftype = Scalar::Util::reftype($_); $_ = $reftype eq "HASH" ? {%{ $_ }} : $reftype eq "ARRAY" ? [@{ $_ }] : $reftype eq "SCALAR" ? \(my $copy = ${ $_ }) : $reftype eq "CODE" ? sub { goto &{ $_ } } :(die "Cannot unbless object with type $ref") }
    my $reftype=Scalar::Util::reftype($_)//"";
    if ($reftype eq "ARRAY") { $process_array->($_) }
    elsif ($reftype eq "HASH") { $process_hash->($_) }
    elsif ($ref) { $_ = $ref; $ref = "" }
}
$data
}
;; $cleanser->(shift) }
1;

# END Local::_pci_clean_json

__END__

=pod

=encoding UTF-8

=head1 NAME

reposdb-inline

=head1 VERSION

This document describes version 0.005 of main (from Perl distribution App-reposdb), released on 2017-07-10.

=head1 SYNOPSIS

Usage:

 % reposdb-inline ls [options]
 % reposdb-inline remove-all-tags [options] [repo]
 % reposdb-inline remove-tag [options] [repo] <tags> ...
 % reposdb-inline touch [options] [repo]

=head1 DESCRIPTION

C<repos.db> is a SQLite database that lists repository names along with some
extra data. They have various uses, but my first use-case for this is to store
last commit/status/pull time (updated via a post-commit git hook or C<gitwrap>).
This is useful to speed up like syncing of repositories in C<Git::Bunch> that
wants to find out which of the hundreds/thousand+ git repositories are "the most
recently used" to prioritize these repositories first. Using information from
C<repos.db> is faster than having to C<git status> or even stat() each repository.

=head1 SUBCOMMANDS

=head2 B<ls>

List repositories registered in repos.db.

=head2 B<remove-all-tags>

=head2 B<remove-tag>

=head2 B<touch>

=head1 OPTIONS

C<*> marks required options.

=head2 Common options

=over

=item B<--config-path>=I<filename>

Set path to configuration file.

Can be specified multiple times.

=item B<--config-profile>=I<s>

Set configuration profile to use.

=item B<--format>=I<s>

Choose output format, e.g. json, text.

Default value:

 undef

=item B<--help>, B<-h>, B<-?>

Display help message and exit.

=item B<--json>

Set output format to json.

=item B<--naked-res>

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

    [200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
`--naked-res` so you just get:

    [1,2,3]


=item B<--no-config>

Do not use any configuration file.

=item B<--no-env>

Do not read environment for default options.

=item B<--reposdb-path>=I<s>*

=item B<--subcommands>

List available subcommands.

=item B<--version>, B<-v>

Display program's version and exit.

=back

=head2 Options for subcommand ls

=over

=item B<--detail>, B<-l>

=item B<--has-tag>=I<s@>

Can be specified multiple times.

=item B<--has-tags-json>=I<s>

See C<--has-tag>.

=item B<--lacks-tag>=I<s@>

Can be specified multiple times.

=item B<--lacks-tags-json>=I<s>

See C<--lacks-tag>.

=item B<--sort>=I<s@>

Default value:

 ["name"]

Can be specified multiple times.

=item B<--sorts-json>=I<s>

See C<--sort>.

=back

=head2 Options for subcommand remove-all-tags

=over

=item B<--repo>=I<s>

=back

=head2 Options for subcommand remove-tag

=over

=item B<--repo>=I<s>

=item B<--tag>=I<s@>*

Can be specified multiple times.

=item B<--tags-json>=I<s>

See C<--tag>.

=back

=head2 Options for subcommand touch

=over

=item B<--commit-time>

=item B<--pull-time>

=item B<--repo>=I<s>

=item B<--status-time>

=item B<--to>=I<s>

=back

=head1 COMPLETION

This script has shell tab completion capability with support for several
shells.

=head2 bash

To activate bash completion for this script, put:

 complete -C reposdb-inline reposdb-inline

in your bash startup (e.g. C<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is recommended, however, that you install modules using L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete reposdb-inline 'p/*/`reposdb-inline`/'

in your tcsh startup (e.g. C<~/.tcshrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is also recommended to install C<shcompgen> (see above).

=head2 other shells

For fish and zsh, install C<shcompgen> as described above.

The script comes with a companion shell completer script (L<_reposdb-inline>)
for this script.

=head2 bash

To activate bash completion for this script, put:

 complete -C _reposdb-inline reposdb-inline

in your bash startup (e.g. F<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is recommended, however, that you install modules using L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete reposdb-inline 'p/*/`reposdb-inline`/'

in your tcsh startup (e.g. F<~/.tcshrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is also recommended to install L<shcompgen> (see above).

=head2 other shells

For fish and zsh, install L<shcompgen> as described above.

=head1 CONFIGURATION FILE

This script can read configuration files. Configuration files are in the format of L<IOD>, which is basically INI with some extra features.

By default, these names are searched for configuration filenames (can be changed using C<--config-path>): F<~/.config/reposdb-inline.conf>, F<~/reposdb-inline.conf>, or F</etc/reposdb-inline.conf>.

All found files will be read and merged.

To disable searching for configuration files, pass C<--no-config>.

To put configuration for a certain subcommand only, use a section name like C<[subcommand=NAME]> or C<[SOMESECTION subcommand=NAME]>.

You can put multiple profiles in a single file by using section names like C<[profile=SOMENAME]> or C<[SOMESECTION profile=SOMENAME]> or C<[subcommand=SUBCOMMAND_NAME profile=SOMENAME]> or C<[SOMESECTION subcommand=SUBCOMMAND_NAME profile=SOMENAME]>. Those sections will only be read if you specify the matching C<--config-profile SOMENAME>.

You can also put configuration for multiple programs inside a single file, and use filter C<program=NAME> in section names, e.g. C<[program=NAME ...]> or C<[SOMESECTION program=NAME]>. The section will then only be used when the reading program matches.

Finally, you can filter a section by environment variable using the filter C<env=CONDITION> in section names. For example if you only want a section to be read if a certain environment variable is true: C<[env=SOMEVAR ...]> or C<[SOMESECTION env=SOMEVAR ...]>. If you only want a section to be read when the value of an environment variable has value equals something: C<[env=HOSTNAME=blink ...]> or C<[SOMESECTION env=HOSTNAME=blink ...]>. If you only want a section to be read when the value of an environment variable does not equal something: C<[env=HOSTNAME!=blink ...]> or C<[SOMESECTION env=HOSTNAME!=blink ...]>. If you only want a section to be read when an environment variable contains something: C<[env=HOSTNAME*=server ...]> or C<[SOMESECTION env=HOSTNAME*=server ...]>. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.

List of available configuration parameters:

=head2 Common for all subcommands

 format (see --format)
 naked_res (see --naked-res)
 reposdb_path (see --reposdb-path)

=head2 Configuration for subcommand ls

 detail (see --detail)
 has_tags (see --has-tag)
 lacks_tags (see --lacks-tag)
 sorts (see --sort)

=head2 Configuration for subcommand remove-all-tags

 repo (see --repo)

=head2 Configuration for subcommand remove-tag

 repo (see --repo)
 tags (see --tag)

=head2 Configuration for subcommand touch

 commit_time (see --commit-time)
 pull_time (see --pull-time)
 repo (see --repo)
 status_time (see --status-time)
 to (see --to)

=head1 ENVIRONMENT

=head2 REPOSDB_INLINE_OPT => str

Specify additional command-line options.

=head1 FILES

F<~/.config/reposdb-inline.conf>

F<~/reposdb-inline.conf>

F</etc/reposdb-inline.conf>

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-reposdb>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-reposdb>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-reposdb>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017, 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
