« blib/lib/Langertha/Raider/Provider/Activation.pm
↑ Summary
blib/lib/Langertha/Raider/CLI/Runner.pm »
| 1 | package Langertha::Raider::Hall::CLI; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 59 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Internal dispatcher of the raider hall subcommands | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 59 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 59 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 59 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 59 | ▶ | use Getopt::Long qw( GetOptions ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 59 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 59 | ▶ | use IO::Async::Loop; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 59 | ▶ | use IO::Async::Stream; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 59 | ▶ | use IO::Socket::UNIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 59 | ▶ | use POSIX qw(WNOHANG); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 59 | ▶ | use Socket qw(SOCK_STREAM); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use YAML::PP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 59 | ▶ | use Langertha::Raider::EngineResolver; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 59 | ▶ | use Langertha::Raider::Hall; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 67 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=17 SCAR=29.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 67 | my ($class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 67 | ▶ | if (!@args || $args[0] eq '--help' || $args[0] eq '-h') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not @args or $args[0] eq "--help" or $args[0] eq "-h"
not @args or $args[0] eq "--help"
MC/DC0%0/3
not @args or $args[0] eq "--help" or $args[0] eq "-h"
not @args
$args[0] eq "--help"
$args[0] eq "-h"
Truth table25%1/4
not(A) or B or C
A= not @argsB= $args[0] eq "--help"C= $args[0] eq "-h"
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | print usage(); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 67 | my $cmd = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 67 | ▶ | if ($cmd eq 'init') { return run_init(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 63 | ▶ | if ($cmd eq 'add-raider') { return run_add_raider(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 59 | ▶ | if ($cmd eq 'start') { return run_start(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 51 | ▶ | if ($cmd eq 'stop') { return run_stop(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 45 | ▶ | if ($cmd eq 'status') { return run_status(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 41 | ▶ | if ($cmd eq 'ps') { return run_ps(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 36 | ▶ | if ($cmd eq 'spawn') { return run_spawn(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 28 | ▶ | if ($cmd eq 'attach') { return run_attach(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | ▶ | if ($cmd eq 'logs') { return run_logs(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 16 | ▶ | if ($cmd eq 'kill') { return run_kill(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | ▶ | if ($cmd eq 'session') { return run_session(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | ▶ | if ($cmd eq 'install') { return run_install(@args); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if ($cmd eq 'help') { print usage(); exit 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | die "Unknown subcommand: $cmd\n\n" . usage(); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 43 | ▶ | sub cwd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cwd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 43 | path('.')->absolute->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # DIR is only ever the first positional and is removed from @$args when | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # taken. Where it is the sole positional (start, stop, status, ps, install) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # any existing directory counts, and anything else is an error. Where $need more positionals (NAME, ID) | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # must follow, it counts only if they remain and it looks like a hall, so a | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # NAME or ID that happens to be a directory is not swallowed. | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 58 | ▶ | sub hall_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hall_dir: called CC=10 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 58 | my ( $args, $need ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 58 | ▶ | $need //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$need //= 0
MC/DC100%1/1
$need //= 0
$need
Truth table100%2/2
A
A= $need
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 58 | my $d = $args->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 58 | ▶ | return cwd unless defined $d && $d !~ /^-/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $d and not $d =~ /^-/
MC/DC50%1/2
defined $d and not $d =~ /^-/
defined $d
not $d =~ /^-/
Truth table66%2/3
A and not(B)
A= defined $dB= not $d =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 44 | ▶ | die "Not a directory: $d\n" if !$need && !-d $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$need or -d $d
MC/DC100%2/2
$need or -d $d
$need
-d $d
Truth table100%3/3
A or B
A= $needB= -d $d
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 32 | ▶ | return cwd unless -d $d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | ▶ | return cwd if $need && ( @$args <= $need || !is_hall_dir($d) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$need and @$args <= $need || !is_hall_dir($d)
@$args <= $need or not is_hall_dir($d)
MC/DC66%2/3
$need and @$args <= $need || !is_hall_dir($d)
$need
@$args <= $need
not is_hall_dir($d)
Truth table75%3/4
A and B or not(C)
A= $needB= @$args <= $needC= not is_hall_dir($d)
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 11 | shift @$args; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 11 | return path($d)->absolute->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | sub is_hall_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_hall_dir: called CC=2 SCAR=8.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | my ( $d ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | return -e path($d)->child('.raider-hall.yml') | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
-e path($d)->child('.raider-hall.yml') || -e path($d)->child('.raider-hall.socket')
MC/DC0%0/2
-e path($d)->child('.raider-hall.yml') || -e path($d)->child('.raider-hall.socket')
-e path($d)->child('.raider-hall.yml')
-e path($d)->child('.raider-hall.socket')
Truth table33%1/3
A || B
A= -e path($d)->child('.raider-hall.yml')B= -e path($d)->child('.raider-hall.socket')
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | || -e path($d)->child('.raider-hall.socket'); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 76 | Usage: raider hall <subcommand> [options] | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | Subcommands: | ||||||||||||||||||||||||||||||||||||||||||
| 79 | init Bootstrap a new hall in the current directory | ||||||||||||||||||||||||||||||||||||||||||
| 80 | add-raider NAME Append a raider entry to .raider-hall.yml | ||||||||||||||||||||||||||||||||||||||||||
| 81 | start [DIR] Start the hall daemon (default: cwd) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | stop [DIR] Stop the hall daemon | ||||||||||||||||||||||||||||||||||||||||||
| 83 | status [DIR] Show hall status | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ps [DIR] List running raiders | ||||||||||||||||||||||||||||||||||||||||||
| 85 | spawn [DIR] NAME MISSION Spawn a raider | ||||||||||||||||||||||||||||||||||||||||||
| 86 | attach [DIR] ID Follow a running raider's event stream | ||||||||||||||||||||||||||||||||||||||||||
| 87 | logs [DIR] ID Fetch raider logs | ||||||||||||||||||||||||||||||||||||||||||
| 88 | kill [DIR] ID Terminate a raider | ||||||||||||||||||||||||||||||||||||||||||
| 89 | session reset [DIR] BINDING Start a new session for a binding | ||||||||||||||||||||||||||||||||||||||||||
| 90 | install [DIR] Install systemd user unit | ||||||||||||||||||||||||||||||||||||||||||
| 91 | help Show this help | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | Run 'raider hall <subcommand> --help' for per-command options. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub run_init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_init: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | Getopt::Long::GetOptions(\%opt, 'name=s', 'engine=s', 'persona=s', 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | return print_init_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | my $name = $opt{name}; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | ▶ | if (!$name) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | print "Raider name (e.g. Bjorn, Ragnar, Astrid, Ivar, Lagertha): "; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | $name = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | chomp $name; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | exit 1 unless length $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | my $persona = $opt{persona} // 'caveman'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"persona"} // "caveman"
MC/DC100%1/1
$opt{"persona"} // "caveman"
$opt{"persona"}
Truth table100%2/2
A
A= $opt{"persona"}
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | my $dir = cwd; | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # No --engine: no engine key, the spawned raider decides itself. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | my %yml; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | $yml{longhouse} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 118 | $yml{raiders}{$name} = { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | ($opt{engine} ? (engine => $opt{engine}) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | persona => $persona, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | packs => [], | ||||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | my $cfg_file = path($dir)->child('.raider-hall.yml'); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | if (-f $cfg_file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | die "Refusing to overwrite existing $cfg_file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 3 | $cfg_file->spew_utf8(YAML::PP->new->dump(\%yml)); | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | print "Hall initialised in $dir with raider '$name'.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | print "Start with: raider hall start\n"; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 4 | ▶ | sub run_add_raider { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_add_raider: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | Getopt::Long::GetOptions(\%opt, | |||||||||||||||||||||||||||||||||||||||||
| 140 | 'engine=s', 'persona=s', 'model=s', 'pack=s@', 'help'); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | ▶ | return print_add_raider_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | my $name = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | die "Usage: raider hall add-raider NAME [--engine E] [--persona P] [--model M] [--pack X]...\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | unless $name; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 4 | my $dir = cwd; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | my $cfg_file = path($dir)->child('.raider-hall.yml'); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | die "No .raider-hall.yml found (run: raider hall init)\n" unless -f $cfg_file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | my $yml = YAML::PP->new->load_string($cfg_file->slurp_utf8) // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
"YAML::PP"->new->load_string($cfg_file->slurp_utf8) // {}
MC/DC0%0/1
"YAML::PP"->new->load_string($cfg_file->slurp_utf8) // {}
"YAML::PP"->new->load_string($cfg_file->slurp_utf8)
Truth table50%1/2
A
A= "YAML::PP"->new->load_string($cfg_file->slurp_utf8)
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | ▶ | $yml->{raiders} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$yml{"raiders"} //= {}
MC/DC0%0/1
$$yml{"raiders"} //= {}
$$yml{"raiders"}
Truth table50%1/2
A
A= $$yml{"raiders"}
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | ▶ | if ($yml->{raiders}{$name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | die "Raider '$name' already defined in $cfg_file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | $yml->{raiders}{$name} = { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ($opt{engine} ? (engine => $opt{engine}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 159 | persona => $opt{persona} // 'caveman', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | ($opt{model} ? (model => $opt{model}) : ()), | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | packs => $opt{pack} // [], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%4/4
$opt{"persona"} // "caveman"
$opt{"pack"} // []
MC/DC100%1/1
$opt{"persona"} // "caveman"
$opt{"persona"}
MC/DC100%1/1
$opt{"pack"} // []
$opt{"pack"}
Truth table100%2/2
A
A= $opt{"persona"}
Truth table100%2/2
A
A= $opt{"pack"}
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | $cfg_file->spew_utf8(YAML::PP->new->dump_string($yml)); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | print "Added raider '$name' to $cfg_file.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub print_add_raider_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_add_raider_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 171 | raider hall add-raider NAME [options] | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | Append a raider entry to .raider-hall.yml. | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | Options: | ||||||||||||||||||||||||||||||||||||||||||
| 176 | --engine NAME Engine (default: none, the raider decides) | ||||||||||||||||||||||||||||||||||||||||||
| 177 | --persona NAME A pack used as the raider's persona (default: caveman) | ||||||||||||||||||||||||||||||||||||||||||
| 178 | --model NAME Model override | ||||||||||||||||||||||||||||||||||||||||||
| 179 | --pack NAME Additional pack (repeatable) | ||||||||||||||||||||||||||||||||||||||||||
| 180 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub print_init_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_init_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | raider hall init [--name NAME] [--engine ENGINE] [--persona PERSONA] | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | Bootstrap a new hall directory with a starter .raider-hall.yml. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | Prompts interactively if --name not provided. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | Options: | ||||||||||||||||||||||||||||||||||||||||||
| 192 | --name NAME Name of the first raider | ||||||||||||||||||||||||||||||||||||||||||
| 193 | --engine NAME Engine (default: none, the raider decides) | ||||||||||||||||||||||||||||||||||||||||||
| 194 | --persona NAME A pack used as the raider's persona (default: caveman) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | ▶ | sub run_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_start: called CC=13 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 8 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 8 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 8 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | Getopt::Long::GetOptions(\%opt, 'daemon', 'acp-port=i', 'acp-host=s', 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 8 | ▶ | return print_start_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 8 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 8 | my $dir = hall_dir(\@args); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | $dir = path($dir); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # --acp-port wins over yml; persist nothing, pass through env. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | ▶ | if (defined $opt{'acp-port'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | $ENV{RAIDER_HALL_ACP_PORT} = $opt{'acp-port'}; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | $ENV{RAIDER_HALL_ACP_HOST} = $opt{'acp-host'} if defined $opt{'acp-host'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | my $pidfile = $dir->child('.raider-hall.pid'); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | if (-f $pidfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | my $pid = eval { $pidfile->slurp_utf8 }; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | if ($pid && $pid =~ /^\d+$/ && kill(0, $pid)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$pid and $pid =~ /^\d+$/ and kill 0, $pid
$pid and $pid =~ /^\d+$/
MC/DC0%0/3
$pid and $pid =~ /^\d+$/ and kill 0, $pid
$pid
$pid =~ /^\d+$/
kill 0, $pid
Truth table25%1/4
A and B and C
A= $pidB= $pid =~ /^\d+$/C= kill 0, $pid
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | die "Hall already running with PID $pid\n"; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 3 | my $hall = Langertha::Raider::Hall->new(root => $dir); | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ($opt{daemon}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $pid = fork; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | die "fork failed: $!" unless defined $pid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($pid != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | print "Hall started with PID $pid\n"; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | POSIX::setsid() or die "setsid: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | open STDIN, '<', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | open STDOUT, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | open STDERR, '>', '/dev/null'; | |||||||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $hall->_write_pidfile; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | eval { $hall->run }; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | die "Hall error: $@\n"; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub print_start_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_start_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 251 | raider hall start [DIR] [--daemon] [--acp-port N] [--acp-host H] | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | Start the hall daemon in DIR (default: cwd). | ||||||||||||||||||||||||||||||||||||||||||
| 254 | --daemon Fork to background | ||||||||||||||||||||||||||||||||||||||||||
| 255 | --acp-port N Enable ACP adapter on TCP port N (127.0.0.1) | ||||||||||||||||||||||||||||||||||||||||||
| 256 | --acp-host H Bind ACP to H (default: 127.0.0.1; use 0.0.0.0 for all) | ||||||||||||||||||||||||||||||||||||||||||
| 257 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | ▶ | sub run_stop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_stop: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | my (@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | my $dir = hall_dir(\@args); | |||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | $dir = path($dir); | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 4 | my $pidfile = $dir->child('.raider-hall.pid'); | |||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | ▶ | if (!-f $pidfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | die "No PID file found. Is the hall running?\n"; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | my $pid = eval { $pidfile->slurp_utf8 }; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | if (!$pid || $pid !~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pid and $pid =~ /^\d+$/
MC/DC50%1/2
$pid and $pid =~ /^\d+$/
$pid
$pid =~ /^\d+$/
Truth table66%2/3
A and B
A= $pidB= $pid =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | die "Invalid PID file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | ▶ | kill 'TERM', $pid or die "Failed to send TERM to $pid: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | print "Sent TERM to hall PID $pid\n"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | sub run_status { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_status: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | my (@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | my $dir = hall_dir(\@args); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 2 | my $result = _send_command($socket, { type => 'command', payload => { cmd => 'status' } }); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 2 | print JSON::MaybeXS->new(pretty => 1)->encode($result), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 5 | ▶ | sub run_ps { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_ps: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 5 | my (@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 292 | 5 | my $dir = hall_dir(\@args); | |||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | my $result = _send_command($socket, { type => 'command', payload => { cmd => 'ps' } }); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 3 | ▶ | my $list = $result->{raiders} // []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$result{"raiders"} // []
MC/DC0%0/1
$$result{"raiders"} // []
$$result{"raiders"}
Truth table50%1/2
A
A= $$result{"raiders"}
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | if (!@$list) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | print "No running raiders.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 300 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | printf "%-10s %-8s %s\n", 'SLOT', 'PID', 'BASE_NAME'; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | for my $r (@$list) { | |||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | printf "%-10s %-8s %s\n", $r->{slot}, $r->{pid}, $r->{base_name}; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub _send_command { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_send_command: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my ($socket_path, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | my $sock = IO::Socket::UNIX->new( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | Type => SOCK_STREAM, | ||||||||||||||||||||||||||||||||||||||||||
| 314 | Peer => $socket_path, | ||||||||||||||||||||||||||||||||||||||||||
| 315 | ) or die "Cannot connect to $socket_path: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||||||
| 318 | my $stream = IO::Async::Stream->new( | ||||||||||||||||||||||||||||||||||||||||||
| 319 | handle => $sock, | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | on_read => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my ($stream, $bufref, $eof) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($$bufref =~ s/^(.*?)\n//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $result = JSON::MaybeXS->new->decode($1); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $stream->loop->stop; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return length($1); | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 328 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $loop = IO::Async::Loop->new; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $loop->add($stream); | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | my $json = JSON::MaybeXS->new->encode($msg); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $stream->write("$json\n"); | |||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $loop->run; | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | die "No response from hall\n" unless defined $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 8 | ▶ | sub run_spawn { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_spawn: called CC=11 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 8 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 8 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 8 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 8 | Getopt::Long::GetOptions(\%opt, 'attach', 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 348 | 8 | ▶ | return print_spawn_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 8 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 8 | my $dir = hall_dir(\@args, 2); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 8 | ▶ | die "Usage: raider hall spawn NAME MISSION [--attach]\n" unless @args >= 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 8 | my $name = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 355 | 8 | my $mission = join ' ', @args; | |||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||
| 357 | 8 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 8 | my $result = _send_command($socket, { | |||||||||||||||||||||||||||||||||||||||||
| 361 | type => 'command', | ||||||||||||||||||||||||||||||||||||||||||
| 362 | payload => { | ||||||||||||||||||||||||||||||||||||||||||
| 363 | cmd => 'spawn', | ||||||||||||||||||||||||||||||||||||||||||
| 364 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | mission => $mission, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 367 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | if ($result->{queued}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | print "Mission queued for slot $result->{slot} (queue depth: $result->{queue_depth}).\n"; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | print STDERR "Not attached: the mission has no run yet.\n" if $opt{attach}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | elsif ($result->{id}) { | ||||||||||||||||||||||||||||||||||||||||||
| 374 | # Attached, stdout is the event stream alone. | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 6 | ▶ | my $out = $opt{attach} ? \*STDERR : \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 6 | print {$out} "Spawned raider $result->{id} (PID $result->{pid}) in slot $result->{slot}.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 6 | ▶ | if ($opt{attach}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 4 | ▶ | die "Hall: raider $result->{id} has no event stream\n" unless $result->{events_path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | return _follow_file($socket, $result->{id}, $result->{events_path}); | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | elsif ($result->{error}) { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my $e = JSON::MaybeXS->new->decode($result->{error}); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | die "Hall error: $e->{error}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | sub print_spawn_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_spawn_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 391 | raider hall spawn [DIR] NAME MISSION [--attach] | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | Spawn a raider with the given NAME and MISSION in DIR (default: cwd). | ||||||||||||||||||||||||||||||||||||||||||
| 394 | --attach then prints the run's event stream like 'attach' does; a | ||||||||||||||||||||||||||||||||||||||||||
| 395 | mission that waits in a queue has no run yet and is not attached. | ||||||||||||||||||||||||||||||||||||||||||
| 396 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 6 | ▶ | sub run_attach { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_attach: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 6 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 6 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 6 | Getopt::Long::GetOptions(\%opt, 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | ▶ | return print_attach_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 6 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 6 | my $dir = hall_dir(\@args, 1); | |||||||||||||||||||||||||||||||||||||||||
| 409 | 6 | ▶ | die "Usage: raider hall attach ID\n" unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | 6 | my $id = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 413 | 6 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | my $result = _send_command($socket, { | |||||||||||||||||||||||||||||||||||||||||
| 416 | type => 'command', | ||||||||||||||||||||||||||||||||||||||||||
| 417 | payload => { cmd => 'attach', id => $id }, | ||||||||||||||||||||||||||||||||||||||||||
| 418 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 6 | ▶ | if ($result->{error}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | die "Hall: $result->{error}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 5 | ▶ | die "Hall: raider $id has no event stream\n" unless $result->{events_path}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 5 | return _follow_file($socket, $id, $result->{events_path}); | |||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub print_attach_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_attach_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 429 | raider hall attach [DIR] ID | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | Print the event stream of the running raider ID (its --stream-json | ||||||||||||||||||||||||||||||||||||||||||
| 432 | events, one JSON object per line) and keep printing new events until | ||||||||||||||||||||||||||||||||||||||||||
| 433 | the raider has exited. For an ended run, see 'logs'. | ||||||||||||||||||||||||||||||||||||||||||
| 434 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 6 | ▶ | sub run_logs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_logs: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 6 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 6 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 6 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 6 | Getopt::Long::GetOptions(\%opt, 'follow', 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 443 | 6 | ▶ | return print_logs_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 6 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | 6 | my $dir = hall_dir(\@args, 1); | |||||||||||||||||||||||||||||||||||||||||
| 447 | 6 | ▶ | die "Usage: raider hall logs ID [--follow]\n" unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | 6 | my $id = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 6 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 451 | 6 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 6 | ▶ | return _follow_log($socket, $id) if $opt{follow}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 3 | return _print_logs($socket, $id); | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 4 | ▶ | sub _print_logs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_logs: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 4 | my ( $socket, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 4 | my $result = _send_command($socket, { | |||||||||||||||||||||||||||||||||||||||||
| 460 | type => 'command', | ||||||||||||||||||||||||||||||||||||||||||
| 461 | payload => { cmd => 'logs', id => $id }, | ||||||||||||||||||||||||||||||||||||||||||
| 462 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 4 | ▶ | if ($result->{error}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | die "Hall: $result->{error}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 4 | print $result->{log}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | ▶ | sub _follow_log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_follow_log: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 3 | my ( $socket, $id ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 3 | my $result = _send_command($socket, { type => 'command', payload => { cmd => 'attach', id => $id } }); | |||||||||||||||||||||||||||||||||||||||||
| 474 | # Already ended: nothing to follow, print what the hall still has. | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | return _print_logs($socket, $id) if $result->{error}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | return _follow_file($socket, $id, $result->{log_path}); | |||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | # Print a file of the raider and keep printing what is appended, until the | ||||||||||||||||||||||||||||||||||||||||||
| 480 | # hall no longer knows the raider (it exited and was reaped); what it wrote | ||||||||||||||||||||||||||||||||||||||||||
| 481 | # before that is still printed. The CLI talks to the hall over a local UNIX | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # socket, so the path is readable here. | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 5 | ▶ | sub _follow_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_follow_file: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 5 | my ( $socket, $id, $file ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 5 | my $attach = { type => 'command', payload => { cmd => 'attach', id => $id } }; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 5 | local $| = 1; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 5 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 490 | 13 | my $gone = _send_command($socket, $attach)->{error}; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 13 | ▶ | $fh //= path($file)->openr_raw if -f $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fh //= path($file)->openr_raw
MC/DC0%0/2
$fh //= path($file)->openr_raw
$fh
path($file)->openr_raw
Truth table66%2/3
A //= B
A= $fhB= path($file)->openr_raw
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 13 | ▶ | if ($fh) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 13 | seek $fh, 0, 1; # clear EOF so appended bytes are seen | |||||||||||||||||||||||||||||||||||||||||
| 494 | 13 | ▶ | while ( read $fh, my $buf, 65536 ) { print $buf } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 13 | ▶ | last if $gone; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 8 | _follow_wait(); | |||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | sub _follow_wait { sleep 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_follow_wait: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | sub print_logs_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_logs_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 506 | raider hall logs [DIR] ID [--follow] | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | Fetch logs for a raider, also after its run has ended: the slot log, or | ||||||||||||||||||||||||||||||||||||||||||
| 509 | the run's result when the slot log no longer has it. --follow keeps | ||||||||||||||||||||||||||||||||||||||||||
| 510 | printing new output until the raider has exited. | ||||||||||||||||||||||||||||||||||||||||||
| 511 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 3 | ▶ | sub run_kill { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_kill: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 3 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 517 | 3 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 3 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 3 | Getopt::Long::GetOptions(\%opt, 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 520 | 3 | ▶ | return print_kill_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 3 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 3 | my $dir = hall_dir(\@args, 1); | |||||||||||||||||||||||||||||||||||||||||
| 524 | 3 | ▶ | die "Usage: raider hall kill ID\n" unless @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 3 | my $id = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 3 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 528 | 3 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | 3 | my $result = _send_command($socket, { | |||||||||||||||||||||||||||||||||||||||||
| 531 | type => 'command', | ||||||||||||||||||||||||||||||||||||||||||
| 532 | payload => { cmd => 'kill', id => $id }, | ||||||||||||||||||||||||||||||||||||||||||
| 533 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 3 | ▶ | if ($result->{killed}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | print "Killed raider $id.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||
| 538 | elsif ($result->{error}) { | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | die "Hall: $result->{error}\n"; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | ▶ | sub print_kill_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_kill_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 546 | raider hall kill [DIR] ID | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | Terminate a raider. | ||||||||||||||||||||||||||||||||||||||||||
| 549 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | 4 | ▶ | sub run_session { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_session: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 4 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 556 | 4 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | Getopt::Long::GetOptions(\%opt, 'help'); | |||||||||||||||||||||||||||||||||||||||||
| 558 | 4 | ▶ | return print_session_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 4 | @args = @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 4 | my $usage = "Usage: raider hall session reset [DIR] BINDING\n"; | |||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | ▶ | my $sub = shift @args // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift @args // ""
MC/DC0%0/1
shift @args // ""
shift @args
Truth table50%1/2
A
A= shift @args
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 4 | ▶ | die $usage unless $sub eq 'reset'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 3 | my $dir = hall_dir(\@args, 1); | |||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | die $usage unless @args == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 2 | my $binding = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 568 | 2 | my $socket = path($dir)->child('.raider-hall.socket'); | |||||||||||||||||||||||||||||||||||||||||
| 569 | 2 | ▶ | die "Hall not running (no socket found)\n" unless -e $socket; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | my $result = _send_command($socket, { | |||||||||||||||||||||||||||||||||||||||||
| 572 | type => 'command', | ||||||||||||||||||||||||||||||||||||||||||
| 573 | payload => { cmd => 'session_reset', binding => $binding }, | ||||||||||||||||||||||||||||||||||||||||||
| 574 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | die "Hall: $result->{error}\n" if $result->{error}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | print 'Binding '.$binding.' reset: its next mission starts a new session' | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | .' (the old one, '.$result->{session}.', is kept).'."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | sub print_session_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_session_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 583 | raider hall session reset [DIR] BINDING | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | Start BINDING over: its next mission runs in a new session. BINDING is a | ||||||||||||||||||||||||||||||||||||||||||
| 586 | key of .raider-hall/state/sessions.json, e.g. telegram:ops:42, | ||||||||||||||||||||||||||||||||||||||||||
| 587 | telegram:ops:-1001234:7, cron:nightly, slot:1bjorn. The old journal is | ||||||||||||||||||||||||||||||||||||||||||
| 588 | kept. In a Telegram chat, /new does the same for that chat. | ||||||||||||||||||||||||||||||||||||||||||
| 589 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 9 | ▶ | sub run_install { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_install: called CC=15 SCAR=32.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 594 | 9 | my (@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 595 | 9 | my %opt; | |||||||||||||||||||||||||||||||||||||||||
| 596 | 9 | local @ARGV = @args; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 9 | Getopt::Long::GetOptions(\%opt, | |||||||||||||||||||||||||||||||||||||||||
| 598 | 'docker', 'host', 'image=s', 'name=s', | ||||||||||||||||||||||||||||||||||||||||||
| 599 | 'acp-port=i', 'acp-host=s', 'stdout', 'help'); | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 9 | ▶ | return print_install_help() if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | 9 | my $dir = hall_dir(\@ARGV); | |||||||||||||||||||||||||||||||||||||||||
| 603 | 7 | $dir = path($dir); | |||||||||||||||||||||||||||||||||||||||||
| 604 | 7 | my $cwd = $dir->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 7 | ▶ | my $unit_name = $opt{name} // 'raider-hall'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"name"} // "raider-hall"
MC/DC100%1/1
$opt{"name"} // "raider-hall"
$opt{"name"}
Truth table100%2/2
A
A= $opt{"name"}
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | 7 | ▶ | my $in_container = -f '/.dockerenv' || ($ENV{container} // '') ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition20%1/5
-f '/.dockerenv' || ($ENV{'container'} // '') ne ''
$ENV{"container"} // ""
MC/DC0%0/2
-f '/.dockerenv' || ($ENV{'container'} // '') ne ''
-f '/.dockerenv'
$ENV{"container"}
Truth table33%1/3
A || B
A= -f '/.dockerenv'B= $ENV{"container"}
| |||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | # The hard truth: systemd lives on the host. Writing to | ||||||||||||||||||||||||||||||||||||||||||
| 609 | # ~/.config/systemd/user/ from inside a container puts the unit in | ||||||||||||||||||||||||||||||||||||||||||
| 610 | # the container's filesystem where no systemd will ever read it. | ||||||||||||||||||||||||||||||||||||||||||
| 611 | # So: inside a container, we *always* emit to stdout and tell the | ||||||||||||||||||||||||||||||||||||||||||
| 612 | # user where to put it. The choice of --docker vs --host only | ||||||||||||||||||||||||||||||||||||||||||
| 613 | # changes the template. | ||||||||||||||||||||||||||||||||||||||||||
| 614 | # | ||||||||||||||||||||||||||||||||||||||||||
| 615 | # Outside a container we write to ~/.config by default, unless | ||||||||||||||||||||||||||||||||||||||||||
| 616 | # --stdout is explicitly requested. | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 7 | ▶ | if ($in_container && !$opt{docker} && !$opt{host}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$in_container and not $opt{"docker"} and not $opt{"host"}
$in_container and not $opt{"docker"}
MC/DC66%2/3
$in_container and not $opt{"docker"} and not $opt{"host"}
$in_container
not $opt{"docker"}
not $opt{"host"}
Truth table75%3/4
A and not(B) and not(C)
A= $in_containerB= not $opt{"docker"}C= not $opt{"host"}
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | die "Detected container environment (/.dockerenv present).\n" | |||||||||||||||||||||||||||||||||||||||||
| 619 | . "Pick one:\n" | ||||||||||||||||||||||||||||||||||||||||||
| 620 | . " --docker emit a unit that runs `docker run` on the host\n" | ||||||||||||||||||||||||||||||||||||||||||
| 621 | . " (install it on the HOST — systemd isn't in here)\n" | ||||||||||||||||||||||||||||||||||||||||||
| 622 | . " --host emit a native unit that execs the in-container raider\n" | ||||||||||||||||||||||||||||||||||||||||||
| 623 | . " (only makes sense if you also bind-mount\n" | ||||||||||||||||||||||||||||||||||||||||||
| 624 | . " ~/.config/systemd/user into the container)\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | my $unit_content = $opt{docker} | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 5 | ▶ | ? _render_docker_unit($cwd, $unit_name, \%opt) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | : _render_native_unit($cwd, \%opt); | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 5 | ▶ | if ($opt{stdout}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 3 | print $unit_content; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||
| 636 | # Inside a container: write to `$root/.raider-hall/systemd/…` — the | ||||||||||||||||||||||||||||||||||||||||||
| 637 | # working dir is almost always a bind-mount from the host, so the | ||||||||||||||||||||||||||||||||||||||||||
| 638 | # file shows up in the user's project tree and a single `ln -s` (or | ||||||||||||||||||||||||||||||||||||||||||
| 639 | # `cp`) from the host pulls it into ~/.config/systemd/user/. | ||||||||||||||||||||||||||||||||||||||||||
| 640 | 2 | ▶ | if ($in_container) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 2 | my $staging = $dir->child('.raider-hall', 'systemd'); | |||||||||||||||||||||||||||||||||||||||||
| 642 | 2 | ▶ | $staging->mkpath unless -d $staging; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | my $unit_file = $staging->child("$unit_name.service"); | |||||||||||||||||||||||||||||||||||||||||
| 644 | 2 | $unit_file->spew_utf8($unit_content); | |||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | 2 | print "Wrote $unit_file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 647 | 2 | print "(inside a container — systemd lives on the host)\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 2 | print "On the HOST, run:\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | print " cp .raider-hall/systemd/$unit_name.service ~/.config/systemd/user/\n"; | |||||||||||||||||||||||||||||||||||||||||
| 650 | 2 | print " systemctl --user daemon-reload\n"; | |||||||||||||||||||||||||||||||||||||||||
| 651 | 2 | print " systemctl --user enable --now $unit_name\n"; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | ▶ | my $xdg = $ENV{XDG_CONFIG_HOME} // path($ENV{HOME})->child('.config'); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ENV{"XDG_CONFIG_HOME"} // path($ENV{"HOME"})->child(".config")
MC/DC0%0/2
$ENV{"XDG_CONFIG_HOME"} // path($ENV{"HOME"})->child(".config")
$ENV{"XDG_CONFIG_HOME"}
path($ENV{"HOME"})->child(".config")
Truth table0%0/3
A // B
A= $ENV{"XDG_CONFIG_HOME"}B= path($ENV{"HOME"})->child(".config")
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | my $systemd_dir = path($xdg)->child('systemd', 'user'); | |||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | $systemd_dir->mkpath unless -d $systemd_dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $unit_file = $systemd_dir->child("$unit_name.service"); | |||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | $unit_file->spew_utf8($unit_content); | |||||||||||||||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | print "Installed $unit_file\n"; | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | ▶ | if ($opt{docker}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | print "(docker-mode unit — docker must be available on this host)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | print "Run:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | print " systemctl --user daemon-reload\n"; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | print " systemctl --user enable --now $unit_name\n"; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 4 | ▶ | sub _render_native_unit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_native_unit: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 4 | my ($cwd, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 4 | my $raider_bin = path($0)->absolute->stringify; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 4 | my @start = ($raider_bin, 'hall', 'start'); | |||||||||||||||||||||||||||||||||||||||||
| 675 | 4 | ▶ | push @start, '--acp-port', $opt->{'acp-port'} if $opt->{'acp-port'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 4 | ▶ | push @start, '--acp-host', $opt->{'acp-host'} if $opt->{'acp-host'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 4 | ▶ | my $exec = join ' ', map { /\s/ ? qq("$_") : $_ } @start; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||
| 679 | 4 | return <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 680 | [Unit] | ||||||||||||||||||||||||||||||||||||||||||
| 681 | Description=Raider Hall daemon | ||||||||||||||||||||||||||||||||||||||||||
| 682 | After=network.target | ||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | [Service] | ||||||||||||||||||||||||||||||||||||||||||
| 685 | Type=simple | ||||||||||||||||||||||||||||||||||||||||||
| 686 | WorkingDirectory=$cwd | ||||||||||||||||||||||||||||||||||||||||||
| 687 | ExecStart=$exec | ||||||||||||||||||||||||||||||||||||||||||
| 688 | Restart=on-failure | ||||||||||||||||||||||||||||||||||||||||||
| 689 | RestartSec=5 | ||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | [Install] | ||||||||||||||||||||||||||||||||||||||||||
| 692 | WantedBy=default.target | ||||||||||||||||||||||||||||||||||||||||||
| 693 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | ▶ | sub _render_docker_unit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_docker_unit: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | my ($cwd, $unit_name, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 698 | 1 | ▶ | my $image = $opt->{image} // 'raudssus/raider:latest'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$opt{"image"} // "raudssus/raider:latest"
MC/DC0%0/1
$$opt{"image"} // "raudssus/raider:latest"
$$opt{"image"}
Truth table50%1/2
A
A= $$opt{"image"}
| |||||||||||||||||||||||||||||||||||||||||||
| 699 | 1 | my $container_name = $unit_name; | |||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | my @docker = ( | |||||||||||||||||||||||||||||||||||||||||
| 702 | '/usr/bin/docker', 'run', '--rm', | ||||||||||||||||||||||||||||||||||||||||||
| 703 | '--name', $container_name, | ||||||||||||||||||||||||||||||||||||||||||
| 704 | '-v', "$cwd:/work", | ||||||||||||||||||||||||||||||||||||||||||
| 705 | '-w', '/work', | ||||||||||||||||||||||||||||||||||||||||||
| 706 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | # Publish the ACP port out of the container when asked for. | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 1 | ▶ | if ($opt->{'acp-port'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | push @docker, '-p', "$opt->{'acp-port'}:$opt->{'acp-port'}"; | |||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | # Forward the API-key env vars — systemd EnvironmentFile is the | ||||||||||||||||||||||||||||||||||||||||||
| 714 | # cleaner long-term answer, but -e on the docker command line is | ||||||||||||||||||||||||||||||||||||||||||
| 715 | # explicit and survives without extra files. | ||||||||||||||||||||||||||||||||||||||||||
| 716 | 1 | for my $e (api_key_env_vars()) { | |||||||||||||||||||||||||||||||||||||||||
| 717 | 13 | push @docker, '-e', $e; | |||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||
| 720 | 1 | push @docker, $image, 'hall', 'start'; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 1 | ▶ | push @docker, '--acp-port', $opt->{'acp-port'} if $opt->{'acp-port'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 722 | push @docker, '--acp-host', ($opt->{'acp-host'} // '0.0.0.0') | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 1 | ▶ | if $opt->{'acp-port'}; # inside container must bind to 0.0.0.0 to be reachable | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$opt{"acp-host"} // "0.0.0.0"
MC/DC0%0/1
$$opt{"acp-host"} // "0.0.0.0"
$$opt{"acp-host"}
Truth table50%1/2
A
A= $$opt{"acp-host"}
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | 1 | ▶ | my $exec_start = join ' ', map { /\s/ ? qq("$_") : $_ } @docker; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 1 | my $exec_stop = qq(/usr/bin/docker stop $container_name); | |||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | 1 | return <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 729 | [Unit] | ||||||||||||||||||||||||||||||||||||||||||
| 730 | Description=Raider Hall daemon (Docker) | ||||||||||||||||||||||||||||||||||||||||||
| 731 | Requires=docker.service | ||||||||||||||||||||||||||||||||||||||||||
| 732 | After=docker.service network.target | ||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | [Service] | ||||||||||||||||||||||||||||||||||||||||||
| 735 | Type=simple | ||||||||||||||||||||||||||||||||||||||||||
| 736 | WorkingDirectory=$cwd | ||||||||||||||||||||||||||||||||||||||||||
| 737 | ExecStartPre=-/usr/bin/docker stop $container_name | ||||||||||||||||||||||||||||||||||||||||||
| 738 | ExecStartPre=-/usr/bin/docker rm $container_name | ||||||||||||||||||||||||||||||||||||||||||
| 739 | ExecStart=$exec_start | ||||||||||||||||||||||||||||||||||||||||||
| 740 | ExecStop=$exec_stop | ||||||||||||||||||||||||||||||||||||||||||
| 741 | Restart=on-failure | ||||||||||||||||||||||||||||||||||||||||||
| 742 | RestartSec=5 | ||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | [Install] | ||||||||||||||||||||||||||||||||||||||||||
| 745 | WantedBy=default.target | ||||||||||||||||||||||||||||||||||||||||||
| 746 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | # The engines' key variables come from the resolver that picks the | ||||||||||||||||||||||||||||||||||||||||||
| 750 | # engine inside the raider; the web-search keys are WebTools'. | ||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | ▶ | sub api_key_env_vars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
api_key_env_vars: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 753 | 1 | Langertha::Raider::EngineResolver->api_key_env_vars, | |||||||||||||||||||||||||||||||||||||||||
| 754 | qw( BRAVE_API_KEY SERPER_API_KEY GOOGLE_API_KEY GOOGLE_CSE_ID ) | ||||||||||||||||||||||||||||||||||||||||||
| 755 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | sub print_install_help { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_install_help: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | print <<"EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 760 | raider hall install [DIR] [options] | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | Write a systemd user unit that starts the hall daemon. | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | Options: | ||||||||||||||||||||||||||||||||||||||||||
| 765 | --docker Emit a Docker unit (docker run raudssus/raider …) | ||||||||||||||||||||||||||||||||||||||||||
| 766 | --host Emit a native unit even inside a container | ||||||||||||||||||||||||||||||||||||||||||
| 767 | (overrides the safety check) | ||||||||||||||||||||||||||||||||||||||||||
| 768 | --image IMG Docker image (default: raudssus/raider:latest) | ||||||||||||||||||||||||||||||||||||||||||
| 769 | --name NAME Unit / container name (default: raider-hall) | ||||||||||||||||||||||||||||||||||||||||||
| 770 | --acp-port N Pass --acp-port N to raider hall start; for --docker | ||||||||||||||||||||||||||||||||||||||||||
| 771 | this also publishes the port out of the container | ||||||||||||||||||||||||||||||||||||||||||
| 772 | --acp-host H Pass --acp-host H to raider hall start | ||||||||||||||||||||||||||||||||||||||||||
| 773 | --stdout Print the unit to stdout instead of writing it | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | Inside a container, --docker or --host must be chosen explicitly — | ||||||||||||||||||||||||||||||||||||||||||
| 776 | otherwise the unit would point at container-internal paths the host | ||||||||||||||||||||||||||||||||||||||||||
| 777 | cannot reach. | ||||||||||||||||||||||||||||||||||||||||||
| 778 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||
| 780 | } | ||||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | 59 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||
| 786 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | Langertha::Raider::Hall::CLI - Internal dispatcher of the raider hall subcommands | ||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||
| 796 | version 0.503 | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | B<Internal module.> Its interface may change without notice. | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | Dispatches the C<raider hall> subcommands: it reads the subcommand and its | ||||||||||||||||||||||||||||||||||||||||||
| 803 | options and runs the matching handler -- C<init> and C<add-raider> to set up | ||||||||||||||||||||||||||||||||||||||||||
| 804 | a L<Langertha::Raider::Hall>, C<start> and C<stop> for its daemon, and | ||||||||||||||||||||||||||||||||||||||||||
| 805 | C<status>, C<ps>, C<spawn>, C<attach>, C<logs>, C<kill>, C<session> and | ||||||||||||||||||||||||||||||||||||||||||
| 806 | C<install> to drive a running hall over its control socket. | ||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | =head2 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||
| 812 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||||||||||
| 813 | L<https://github.com/Getty/langertha-raider/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | =head2 IRC | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||
| 821 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||
| 823 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | Torsten Raudssus <torsten@raudssus.de> L<https://raudssus.de/> | ||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | This software is copyright (c) 2026 by Torsten Raudssus. | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 832 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | =cut | ||||||||||||||||||||||||||||||||||||||||||