App-karr
view release on metacpan or search on metacpan
bin/karr-foundation view on Meta::CPAN
#!/usr/bin/env perl
# PODNAME: karr-foundation
# ABSTRACT: Single-shot foundation daemon for periodic karr agent execution
use strict;
use warnings;
our $VERSION = '0.600';
use App::karr::Foundation;
use App::karr::Encoding qw( decode_argv enable_std_utf8 );
use App::karr::Error qw( is_usage_error );
# Same character/octet boundary as F<karr> (ticket #53). The agent output this
# tees to the terminal is raw bytes and is decoded incrementally in
# App::karr::Foundation::Runner, not here.
enable_std_utf8();
decode_argv();
# What is left of @ARGV after option parsing is the hub command, if any
# (`ask`, `answer`, `chain`, `plan`) -- see App::karr::Foundation::run. MooX::Options is
# configured with protect_argv => 0 in that class, which is what makes the
# leftovers visible here.
# An option name with a dash in it does not survive standing behind a boolean
# flag, so the flags are respelled with underscores before MooX::Options looks
# at argv (ticket #256). F<bin/karr> does the same one step earlier, because it
# has to pick the command class first; here there is only one option table, so
# the call is the whole of it. App::karr::Role::CliArgs/normalize_option_argv
# carries the diagnosis and the condition under which the call may go again.
@ARGV = App::karr::Foundation->normalize_option_argv( \@ARGV );
my $exit;
my $ran = eval {
my $foundation = App::karr::Foundation->new_with_options;
$exit = $foundation->run(@ARGV);
1;
};
if ( !$ran ) {
my $err = $@;
# Exit-code contract (ADR 0002): 0 success / 1 runtime failure / 2 usage
# error. The same central handler F<karr> has, for the same reason: without
# it an uncaught die leaves perl to pick the status -- 255, or whatever
# errno happens to hold -- so every user_error this binary raises reached
# its caller as an accident. A broken config file, an unknown mode and
# (since #191) `karr-foundation answer 7 x` on a question that already has
# an answer were all that accident; this binary is typed at and scripted
# like the CLI is, so it belongs to the same contract (ticket #201).
#
# The usage-versus-runtime split is decided by
# App::karr::Error::is_usage_error, on the same stable leading markers
# F<karr> documents -- "Unknown command:", "unexpected extra argument",
# "Usage:", "Usage error:". A new usage-error die here must start with one
# of them; everything else -- a config that will not parse, a question that
# is already answered, a Git failure -- is a runtime failure (1).
#
# Option-parse errors never reach here: MooX::Options exits 2 directly via
# App::karr::Role::ExitCodes, which App::karr::Foundation composes for it,
# and that exit bypasses this eval.
print STDERR $err if defined $err && length $err;
exit( is_usage_error($err) ? 2 : 1 );
}
exit $exit;
__END__
=pod
=encoding UTF-8
=head1 NAME
karr-foundation - Single-shot foundation daemon for periodic karr agent execution
=head1 VERSION
( run in 2.061 seconds using v1.01-cache-2.11-cpan-364913b4093 )