| 1 | package Skilletor::CLI; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: The skilletor command line – arguments, usage, exit codes (spec §7) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 232 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 232 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 232 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 232 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 232 | our $VERSION = '0.008000'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 232 | our @EXPORT_OK = qw( run parse_flags unknown_option project_root_of self_command is_packed USAGE ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # Every module beyond Exporter is loaded by the first call that needs it (k199): --version and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # --help load nothing else, nor does a usage error; a hook loads its own. Each helper below | ||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # loads its module and hands over the call as it was. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 81 | ▶ | sub decode_utf8_lossy { require Skilletor::FSUtil; goto &Skilletor::FSUtil::decode_utf8_lossy } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_utf8_lossy: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 24 | ▶ | sub path_join { require Skilletor::FSUtil; goto &Skilletor::FSUtil::path_join } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path_join: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 335 | ▶ | sub project_root_of { require Skilletor::Hooks; goto &Skilletor::Hooks::project_root_of } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
project_root_of: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub js_ordered { require Skilletor::JSON; goto &Skilletor::JSON::js_ordered } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
js_ordered: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | ▶ | sub js_parse { require Skilletor::JSON; goto &Skilletor::JSON::js_parse } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
js_parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | ▶ | sub js_stringify { require Skilletor::JSON; goto &Skilletor::JSON::js_stringify } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
js_stringify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 31 | ▶ | sub js_type { require Skilletor::JSON; goto &Skilletor::JSON::js_type } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
js_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub backend_label { require Skilletor::Report; goto &Skilletor::Report::backend_label } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
backend_label: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 62 | ▶ | sub report_json { require Skilletor::Report; goto &Skilletor::Report::report_json } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_json: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 623 | ▶ | sub report_text { require Skilletor::Report; goto &Skilletor::Report::report_text } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report_text: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub status_text { require Skilletor::Report; goto &Skilletor::Report::status_text } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_text: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # A line of printable ASCII and tabs has nothing to escape (t/68-cli.t holds display_safe to | ||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # that), so a usage error loads no report module either. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 532 | ▶ | sub display_safe { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
display_safe: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 532 | ▶ | return $_[0] if defined $_[0] && $_[0] =~ /\A[\t\x20-\x7E]*\z/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[0] and $_[0] =~ /\A[\t\x20-\x7E]*\z/
MC/DC50%1/2
defined $_[0] and $_[0] =~ /\A[\t\x20-\x7E]*\z/
defined $_[0]
$_[0] =~ /\A[\t\x20-\x7E]*\z/
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /\A[\t\x20-\x7E]*\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 177 | require Skilletor::Report; | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 177 | goto &Skilletor::Report::display_safe; | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # An argument as Encode::decode reads it, Encode loaded for one that is not ASCII alone: ASCII | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # decodes to itself, a character string. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 202 | ▶ | sub _decode { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 202 | my ( $bytes ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 202 | ▶ | return undef unless defined $bytes; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 202 | ▶ | if ( $bytes =~ /[^\x00-\x7F]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return Encode::decode( 'UTF-8', $bytes ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 201 | utf8::upgrade( my $text = $bytes ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 201 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # The version the CLI reports is the dist's, $VERSION above: x.yyyzzz is the plugin's x.y.z | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # (package.json; 0.008000 is 0.8.0), which t/02-version.t ties to it. The usage text starts with it. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 232 | ▶ | use constant USAGE_BODY => <<'END_USAGE'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Remote skills, agents and rules for Claude Code, Codex and Hermes Agent. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | skilletor <command> [options] | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | Commands: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | sync Reconcile installed items with the config | ||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | check Report whether a sync is due (writes nothing) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | status Show declared vs. installed items | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | add [name] <spec> Add and trust a source, then sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | source list List declared sources | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | source remove <name> Remove a source, then sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | available [source] List items offered by trusted sources | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | install <item>... Install items ([type:]name@source), then sync; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | type:*@source installs every item of that type, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | type:perl-*@source every one whose name matches; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | bundle:name@source installs a bundle (a bare | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | name@source does too when no item has that name); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | sources a bundle needs are offered for adding | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | (on a terminal; otherwise the add commands are shown) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | uninstall <item>... Remove entries ([type:]name@source, type:*@source, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | type:perl-*@source or bundle:name@source), then sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | trust <source> Trust a project-declared source | ||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | --scope <s> user | project | all (default: all; sync, check, status) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | --project Edit the project config instead of the user config | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | (add, install, uninstall, source remove) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | --json Machine-readable output | ||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | (sync, check, status, source list, available) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | --force sync: adopt foreign files on conflict; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | source remove: remove even if items are installed | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | --project-dir <dir> Project root (default: git top level of cwd, else cwd) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | -h, --help Show this help (anywhere; nothing else runs) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | -v, --version Show the version (first argument only) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | An option the command does not accept is an error (exit 2). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | END_USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 12 | ▶ | sub USAGE () { 'skilletor '.$VERSION."\n".USAGE_BODY } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
USAGE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # The options each command accepts (spec §7); --project-dir goes with every one. `hook` is | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # absent: it is internal and must never fail (spec §8). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 232 | my %ACCEPTED = ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sync => [qw( --scope --json --force )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | check => [qw( --scope --json )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | status => [qw( --scope --json )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | add => [qw( --project )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 'source list' => [qw( --json )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 'source remove' => [qw( --project --force )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | available => [qw( --json )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | install => [qw( --project )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | uninstall => [qw( --project )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | trust => [], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # The reference's `source ${rest[0]}`: an absent sub-command is the string "undefined". | ||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 11 | ▶ | sub _source_key { 'source '.( $_[0]{rest}[0] // 'undefined' ) } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_source_key: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{"rest"}[0] // "undefined"
MC/DC100%1/1
$_[0]{"rest"}[0] // "undefined"
$_[0]{"rest"}[0]
Truth table100%2/2
A
A= $_[0]{"rest"}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 58 | ▶ | sub unknown_option { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unknown_option: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 58 | my ( $cmd, $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 58 | ▶ | return undef if $cmd ne 'source' && !exists $ACCEPTED{$cmd}; # unknown command: its own error | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cmd ne "source" and not exists $ACCEPTED{$cmd}
MC/DC100%2/2
$cmd ne "source" and not exists $ACCEPTED{$cmd}
$cmd ne "source"
not exists $ACCEPTED{$cmd}
Truth table100%3/3
A and not(B)
A= $cmd ne "source"B= not exists $ACCEPTED{$cmd}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 56 | ▶ | my $key = $cmd eq 'source' ? _source_key($flags) : $cmd; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # `source` without list/remove keeps its own usage error; any known option is fine there. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 56 | ▶ | my $accepted = $ACCEPTED{$key} // ( $cmd eq 'source' ? [ @{ $ACCEPTED{'source list'} }, @{ $ACCEPTED{'source remove'} } ] : [] ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$ACCEPTED{$key} // ($cmd eq "source" ? [@{$ACCEPTED{"source list"};}, @{$ACCEPTED{"source remove"};}] : [])
MC/DC100%1/1
$ACCEPTED{$key} // ($cmd eq "source" ? [@{$ACCEPTED{"source list"};}, @{$ACCEPTED{"source remove"};}] : [])
$ACCEPTED{$key}
Truth table100%2/2
A
A= $ACCEPTED{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 56 | my %ok = map { ( $_ => 1 ) } @$accepted; | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 56 | ▶ | return ( grep { $_ ne '--project-dir' && !$ok{$_} } @{ $flags->{options} } )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '--project-dir' && !$ok{$_}
MC/DC100%2/2
$_ ne '--project-dir' && !$ok{$_}
$_ ne '--project-dir'
!$ok{$_}
Truth table100%3/3
A && not(B)
A= $_ ne '--project-dir'B= !$ok{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 72 | ▶ | sub parse_flags { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_flags: called CC=11 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 72 | my ( @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 72 | my %flags = ( scope => 'all', json => 0, force => 0, project => 0, project_dir => undef, options => [], rest => [] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 72 | ▶ | for ( my $i = 0; $i < @args; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 82 | my $arg = $args[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 82 | ▶ | push @{ $flags{options} }, ( $arg =~ /\A--/ ? $arg =~ s/=.*//sr : $arg ) if $arg =~ /\A-/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 82 | ▶ | if ( $arg eq '--json' ) { $flags{json} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | elsif ( $arg eq '--force' ) { $flags{force} = 1 } | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | elsif ( $arg eq '--project' ) { $flags{project} = 1 } | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 7 | elsif ( $arg eq '--scope' ) { $flags{scope} = $args[ ++$i ] } # undef past the end | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | elsif ( $arg =~ /\A--scope=(.*)\z/s ) { $flags{scope} = $1 } | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 11 | elsif ( $arg eq '--project-dir' ) { $flags{project_dir} = $args[ ++$i ] } | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | elsif ( $arg =~ /\A--project-dir=(.*)\z/s ) { $flags{project_dir} = $1 } | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 48 | else { push @{ $flags{rest} }, $arg } | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 72 | return \%flags; | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Text to a stream as UTF-8, as Node writes a string. ASCII is its own UTF-8: Encode is loaded | ||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # for other text only. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 266 | ▶ | sub _write { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 266 | my ( $fh, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 266 | ▶ | if ( $text =~ /[^\x00-\x7F]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 136 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 136 | $text = Encode::encode( 'UTF-8', $text ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 266 | print {$fh} $text; | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Display lines, each escaped whole (spec §8), one newline after each. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 218 | ▶ | sub _print_lines { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_lines: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 218 | my ( $fh, @lines ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 218 | _write( $fh, join( "\n", map { display_safe($_) } @lines )."\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Text whose newlines are line breaks, each line escaped. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 134 | ▶ | sub _print_text { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_print_text: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 134 | my ( $fh, $text ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 134 | my @lines = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 134 | ▶ | _print_lines( $fh, @lines ? @lines : ('') ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # A string's truthiness in JavaScript: set and not empty. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 71 | ▶ | sub _truthy { defined $_[0] && length $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_truthy: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Node's os.homedir(): $HOME, else the user's passwd entry. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 34 | ▶ | sub _home { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_home: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 34 | ▶ | return decode_utf8_lossy( $ENV{HOME} ) if defined $ENV{HOME}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my $dir = ( getpwuid $< )[7]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | die "A system error occurred: uv_os_homedir returned ENOENT (no such file or directory)\n" unless defined $dir; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return decode_utf8_lossy($dir); | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # The engine a command runs on, as the reference's makeContext builds it: the home, the project | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # from --project-dir (a relative one taken from cwd: the scope's state is keyed by its absolute lock | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # path, k254) or the git top level of cwd. The rest is the engine's own default, read from this | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # machine: the state root <CLAUDE_CONFIG_DIR or ~/.claude>/skilletor, host and user, the harness | ||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # markers, git's answers. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 22 | ▶ | sub _engine { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_engine: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 22 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 22 | require Skilletor::Engine; # loaded for the commands that run it: --help and usage errors stay fast | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 22 | require Skilletor::FSUtil; | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 22 | my $home = _home(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 22 | my $project_dir = $flags->{project_dir}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 22 | ▶ | unless ( defined $project_dir && ( $project_dir eq '' || Skilletor::FSUtil::is_absolute($project_dir) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $project_dir and $project_dir eq "" || Skilletor::FSUtil::is_absolute($project_dir)
$project_dir eq "" or Skilletor::FSUtil::is_absolute($project_dir)
MC/DC66%2/3
defined $project_dir and $project_dir eq "" || Skilletor::FSUtil::is_absolute($project_dir)
defined $project_dir
$project_dir eq ""
Skilletor::FSUtil::is_absolute($project_dir)
Truth table75%3/4
A and B or C
A= defined $project_dirB= $project_dir eq ""C= Skilletor::FSUtil::is_absolute($project_dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 16 | require Cwd; | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | my $cwd = Cwd::getcwd(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | ▶ | die "the current directory no longer exists; pass --project-dir <dir>\n" unless defined $cwd; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 14 | $cwd = decode_utf8_lossy($cwd); | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | ▶ | $project_dir = defined $project_dir ? Skilletor::FSUtil::path_resolve( $cwd, $project_dir ) : project_root_of($cwd); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 20 | return Skilletor::Engine->new( home => $home, project_dir => $project_dir ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # The sync report, or "up to date" when no scope has anything to say; run-level warnings and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # notes come in addition, never instead (the reference's syncText). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 375 | ▶ | sub _sync_text { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sync_text: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 375 | my ( $r ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 375 | my $text = report_text($r); | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 375 | ▶ | my $run_level = @{ $r->{warnings} // [] } || @{ $r->{notes} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%7/7
@{$r->{'warnings'} // [];} || @{$r->{'notes'} // [];}
$r->{"warnings"} // []
$r->{"notes"} // []
MC/DC100%2/2
@{$r->{'warnings'} // [];} || @{$r->{'notes'} // [];}
@{$r->{'warnings'} // [];}
@{$r->{'notes'} // [];}
MC/DC100%1/1
$r->{"warnings"} // []
$r->{"warnings"}
MC/DC100%1/1
$r->{"notes"} // []
$r->{"notes"}
Truth table100%3/3
A || B
A= @{$r->{'warnings'} // [];}B= @{$r->{'notes'} // [];}
Truth table100%2/2
A
A= $r->{"warnings"}
Truth table100%2/2
A
A= $r->{"notes"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 375 | ▶ | if ($run_level) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 186 | my %scopes_only = %$r; | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 186 | delete @scopes_only{qw( warnings notes )}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 186 | ▶ | return "skilletor: up to date\n$text" unless length report_text( \%scopes_only ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 251 | ▶ | return length $text ? $text : 'skilletor: up to date'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # A sync that stopped at a config error (spec §7): its report on stderr, exit 2. With `saved`, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # the config file the command's edit wrote before the sync: it stays, and the lines say so | ||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # (k103). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 186 | ▶ | sub _sync_failed { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sync_failed: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 186 | my ( $r, %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 186 | ▶ | if ( !defined $opts{saved} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 124 | ▶ | _print_text( \*STDERR, $opts{json} ? report_json($r) : report_text($r) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | _print_lines( \*STDERR, 'skilletor: config error, nothing synced — '.$r->{error}, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 62 | 'skilletor: the config edit itself was saved in '.$opts{saved}.' (not rolled back); fix the error, then run skilletor sync' ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 186 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 5 | ▶ | sub _sync { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sync: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 5 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | my $r = _engine($flags)->sync( scope => $flags->{scope}, force => $flags->{force} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | return _sync_failed( $r, json => $flags->{json} ) if _truthy( $r->{error} ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | ▶ | _print_text( \*STDOUT, $flags->{json} ? report_json($r) : _sync_text($r) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub _check { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $r = _engine($flags)->check( scope => $flags->{scope} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ( _truthy( $r->{error} ) ) { # a line, never JSON – under --json too | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | _print_lines( \*STDERR, 'skilletor: '.$r->{error} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | _print_text( \*STDOUT, $flags->{json} ? report_json($r) : $r->{changed} ? 'changed' : 'up to date' ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return $r->{changed} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | sub _status { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_status: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | my $r = _engine($flags)->status( scope => $flags->{scope} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | _print_text( \*STDOUT, $flags->{json} ? report_json($r) : status_text($r) ); # an error too: stdout, exit 2 | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | return _truthy( $r->{error} ) ? 2 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # The config commands; Skilletor::Commands is loaded for them alone, as the engine is. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | sub _source_list { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_source_list: called CC=2 SCAR=7.3
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | my $list = Skilletor::Commands::source_list($engine); | |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | if ( $flags->{json} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | _print_text( \*STDOUT, js_stringify( $list, 2 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | _print_lines( \*STDOUT, map { $_->{name}.' ['.$_->{origin}.'] '.js_stringify( $_->{def} ) } @$list ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # The added or kept line, then the sync's text. A kept entry wrote nothing to the config: a sync | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # that stopped at a config error says so as sync does. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | ▶ | sub _add { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add: called CC=5 SCAR=23.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | my @rest = @{ $flags->{rest} }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | ▶ | my ( $name, $spec ) = @rest >= 2 ? @rest[ 0, 1 ] : ( undef, $rest[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 1 | my $r = Skilletor::Commands::add( $engine, name => $name, spec => $spec, project => $flags->{project} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $def = js_stringify( $r->{def} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | _print_lines( \*STDOUT, $r->{kept} ? "source $r->{name} already added ($def), kept as is" : "added source $r->{name} ($def)" ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if ( _truthy( $r->{report}{error} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | return _sync_failed( $r->{report}, saved => $r->{kept} ? undef : Skilletor::Commands::config_path( $engine, $flags->{project} ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | _print_text( \*STDOUT, _sync_text( $r->{report} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # The sync's report after the edit, or `removed source <name>` when it has nothing to say. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | sub _source_remove { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_source_remove: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my ( $flags, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $r = Skilletor::Commands::source_remove( $engine, name => $name, project => $flags->{project}, force => $flags->{force} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | return _sync_failed( $r, saved => Skilletor::Commands::config_path( $engine, $flags->{project} ) ) if _truthy( $r->{error} ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $text = report_text($r); | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | _print_text( \*STDOUT, length $text ? $text : display_safe("removed source $name") ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # One line per item – installed mark, type, name@source, description – and a second, indented, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # for an item's error, a bundle's members or why it does not expand; --json the list. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | sub _available { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_available: called CC=8 SCAR=34.4
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 1 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | my $items = Skilletor::Commands::available( $engine, source => $flags->{rest}[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | if ( $flags->{json} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | _print_text( \*STDOUT, js_stringify( $items, 2 ) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | my @lines = map { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $i = $_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | my $line = ( $i->{installed} ? '✓' : ' ' ).' '.$i->{type}.' '.$i->{name}.'@'.$i->{source} | ||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | .( _truthy( $i->{description} ) ? ' — '.$i->{description} : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # An item that cannot be built (spec §4.1) says why on the next line, as a bundle does; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # a bundle's members (spec §15.5) go there, or why it cannot be expanded. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | $i->{type} ne 'bundle' ? ( $line, defined $i->{error} ? ' error: '.$i->{error} : () ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | : defined $i->{error} ? ( $line, ' error: '.$i->{error} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | : ( $line, ' '.( join( ', ', @{ $i->{members} } ) || '(no items)' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/2
join(', ', @{$i->{'members'};}) || '(no items)'
MC/DC0%0/1
join(', ', @{$i->{'members'};}) || '(no items)'
join(', ', @{$i->{'members'};})
Truth table0%0/2
A
A= join(', ', @{$i->{'members'};})
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } @$items; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | _print_lines( \*STDOUT, @lines ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # The sync's text after the edit. A bundle's missing sources are asked for on a terminal. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 11 | ▶ | sub _install { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_install: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 11 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 11 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 11 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 11 | my $r = Skilletor::Commands::install( $engine, items => $flags->{rest}, project => $flags->{project}, prompt => _tty_prompter() ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | ▶ | return _sync_failed( $r, saved => Skilletor::Commands::config_path( $engine, $flags->{project} ) ) if _truthy( $r->{error} ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | _print_text( \*STDOUT, _sync_text($r) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # The sync's text after the edit. A warning names each covering wildcard or bundle that remains. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | ▶ | sub _uninstall { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_uninstall: called CC=3 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | my ( $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 1 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | my $r = Skilletor::Commands::uninstall( $engine, items => $flags->{rest}, project => $flags->{project} ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | _print_lines( \*STDERR, 'skilletor: warning: '.$_ ) for @{ $r->{hints} }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | return _sync_failed( $r->{report}, saved => Skilletor::Commands::config_path( $engine, $flags->{project} ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if _truthy( $r->{report}{error} ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | _print_text( \*STDOUT, _sync_text( $r->{report} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # Questions on the terminal (the reference's ttyPrompter): stdin in, stderr out, so stdout stays | ||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # clean; none unless both are terminals. The end of input (Ctrl+D) and Ctrl+C abort the command | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | # with the message Node's readline gives. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 18 | ▶ | sub _tty_prompter { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tty_prompter: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 18 | ▶ | return undef unless -t STDIN && -t STDERR; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-t STDIN and -t STDERR
MC/DC100%2/2
-t STDIN and -t STDERR
-t STDIN
-t STDERR
Truth table100%3/3
A and B
A= -t STDINB= -t STDERR
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 10 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 10 | my ( $question ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | _write( \*STDERR, display_safe($question).' ' ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | local $SIG{INT} = sub { die "Aborted with Ctrl+C\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | binmode STDIN; | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | my $line = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | ▶ | die "Aborted with Ctrl+D\n" unless defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 9 | $line =~ s/\r?\n\z//; | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 9 | return decode_utf8_lossy($line); | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 10 | }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | sub _trust { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trust: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | my ( $flags, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | my $engine = _engine($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | require Skilletor::Commands; | |||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my $r = Skilletor::Commands::trust( $engine, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | _print_lines( \*STDOUT, 'trusted source '.$r->{name}.' ('.backend_label($r).')' ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # A usage error (spec §7): its line on stderr, exit 2. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 16 | ▶ | sub _usage_error { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 16 | my ( $line ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 16 | _write( \*STDERR, "$line\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 16 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # What a caught error says: a Skilletor::Error's message, else Perl's text without the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # " at FILE line N." it appends. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 8 | ▶ | sub _message { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_message: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 8 | my ( $err ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 8 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | ▶ | return $err->message if Scalar::Util::blessed($err) && $err->can('message'); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($err) and $err->can("message")
MC/DC50%1/2
builtin::blessed($err) and $err->can("message")
builtin::blessed($err)
$err->can("message")
Truth table66%2/3
A and B
A= builtin::blessed($err)B= $err->can("message")
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 5 | my $text = "$err"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 5 | $text =~ s/ at (?:(?! at ).)+ line \d+(?:, <[^>]*> (?:line|chunk) \d+)?\.\n\z//s; | |||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | chomp $text; | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | return $text; | |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | #### hook #################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # Is this a PAR-packed binary? PAR's loader is loaded and names the program in PAR_PROGNAME. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 57 | ▶ | sub is_packed { exists $INC{'PAR.pm'} && _truthy( $ENV{PAR_PROGNAME} ) ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_packed: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
Condition66%2/3
exists $INC{"PAR.pm"} and _truthy($ENV{"PAR_PROGNAME"})
MC/DC50%1/2
exists $INC{"PAR.pm"} and _truthy($ENV{"PAR_PROGNAME"})
exists $INC{"PAR.pm"}
_truthy($ENV{"PAR_PROGNAME"})
Truth table66%2/3
A and B
A= exists $INC{"PAR.pm"}B= _truthy($ENV{"PAR_PROGNAME"})
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # The command line that runs this CLI once more, for the hooks' detached background sync (the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # reference's binPath). A PAR-packed binary is its own program: PAR_PROGNAME, its full path – in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # one, $^X is the bare name `perl` and $0 the name it was called by. Plain perl runs $^X with the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | # script and, as -I, every module dir it searches, so the child finds what this run found. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 48 | ▶ | sub self_command { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
self_command: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 48 | my ( %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 48 | ▶ | my $packed = $args{packed} // is_packed(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"packed"} // is_packed()
MC/DC0%0/2
$args{"packed"} // is_packed()
$args{"packed"}
is_packed()
Truth table66%2/3
A // B
A= $args{"packed"}B= is_packed()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 48 | ▶ | return [ $args{progname} // $ENV{PAR_PROGNAME} ] if $packed; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"progname"} // $ENV{"PAR_PROGNAME"}
MC/DC0%0/2
$args{"progname"} // $ENV{"PAR_PROGNAME"}
$args{"progname"}
$ENV{"PAR_PROGNAME"}
Truth table66%2/3
A // B
A= $args{"progname"}B= $ENV{"PAR_PROGNAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 30 | ▶ | return [ $args{perl} // $^X, ( map { "-I$_" } grep { !ref } @{ $args{inc} // \@INC } ), $args{script} // $0 ]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%6/8
$args{"perl"} // $^X
$args{"inc"} // \@INC
$args{"script"} // $0
MC/DC0%0/2
$args{"perl"} // $^X
$args{"perl"}
$^X
MC/DC100%1/1
$args{"inc"} // \@INC
$args{"inc"}
MC/DC0%0/2
$args{"script"} // $0
$args{"script"}
$0
Truth table66%2/3
A // B
A= $args{"perl"}B= $^X
Truth table100%2/2
A
A= $args{"inc"}
Truth table66%2/3
A // B
A= $args{"script"}B= $0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | # JavaScript's truthiness of a JSON value. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 17 | ▶ | sub _js_truthy { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_js_truthy: called CC=7 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 17 | my ( $v ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 17 | my $type = js_type($v); | |||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 17 | ▶ | return 0 if $type eq 'null'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 5 | ▶ | return length $v ? 1 : 0 if $type eq 'string'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | return $v ? 1 : 0 if $type eq 'number' || $type eq 'boolean'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$type eq "number" or $type eq "boolean"
MC/DC0%0/2
$type eq "number" or $type eq "boolean"
$type eq "number"
$type eq "boolean"
Truth table0%0/3
A or B
A= $type eq "number"B= $type eq "boolean"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # The hook's input: stdin as JSON, nothing on a terminal; malformed input, or JSON that is no | ||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # object, counts as none. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 14 | ▶ | sub _hook_input { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hook_input: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 14 | ▶ | return {} if -t STDIN; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 232 | ▶ | my $raw = do { no warnings; local $/; binmode STDIN; <STDIN> } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Condition50%1/2
do {
no warnings;
local $/;
binmode STDIN;
readline STDIN
} // ""
MC/DC0%0/1
do {
no warnings;
local $/;
binmode STDIN;
readline STDIN
} // ""
do {
no warnings;
local $/;
binmode STDIN;
readline STDIN
}
Truth table50%1/2
A
A= do {
no warnings;
local $/;
binmode STDIN;
readline STDIN
}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 14 | ▶ | my $input = eval { $raw =~ /\S/ ? js_parse( decode_utf8_lossy($raw) ) : undef }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 14 | ▶ | return js_type($input) eq 'object' ? $input : {}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # `skilletor hook <event> [--harness codex|hermes]` (the reference's runHookCommand): stdin JSON | ||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # in, a compact JSON line out when there is something to say, exit 0 always (spec §8). A die in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # its own setup – no home, say (k164) – is that one line as well. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 14 | ▶ | sub _hook { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hook: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 14 | my ( @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 14 | local $SIG{PIPE} = 'IGNORE'; # a reader gone is no reason to exit otherwise | |||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 14 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 14 | ▶ | $out = js_ordered( systemMessage => display_safe( 'skilletor: '._message($@) ) ) unless eval { $out = _hook_output(@args); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 11 | ▶ | if ( ref $out eq 'HASH' && ( _js_truthy( $out->{systemMessage} ) || _js_truthy( $out->{hookSpecificOutput} ) ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $out eq "HASH" and _js_truthy($out->{"systemMessage"}) || _js_truthy($out->{"hookSpecificOutput"})
_js_truthy($out->{"systemMessage"}) or _js_truthy($out->{"hookSpecificOutput"})
MC/DC33%1/3
ref $out eq "HASH" and _js_truthy($out->{"systemMessage"}) || _js_truthy($out->{"hookSpecificOutput"})
ref $out eq "HASH"
_js_truthy($out->{"systemMessage"})
_js_truthy($out->{"hookSpecificOutput"})
Truth table50%2/4
A and B or C
A= ref $out eq "HASH"B= _js_truthy($out->{"systemMessage"})C= _js_truthy($out->{"hookSpecificOutput"})
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 5 | _write( \*STDOUT, js_stringify($out)."\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 11 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 14 | ▶ | sub _hook_output { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hook_output: called CC=10 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 14 | my ( @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 14 | my $event = $args[0]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 14 | my ($at) = grep { $args[$_] eq '--harness' } 0 .. $#args; | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 14 | ▶ | my $harness = defined $at ? $args[ $at + 1 ] : ( map { /\A--harness=(.*)\z/s ? $1 : () } @args )[0]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 14 | ▶ | return undef unless _truthy($event); # nothing to do, never disturb the session | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 14 | my $input = _hook_input(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 14 | my $home = _home(); | |||||||||||||||||||||||||||||||||||||||||||||||
| 446 | # Unset under Codex: the hook then takes the git top level of the input's cwd (spec §14.5). | ||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 12 | ▶ | my ($project_dir) = grep { _truthy($_) } map { defined $_ ? decode_utf8_lossy($_) : undef } @ENV{qw( SKILLETOR_PROJECT_DIR CLAUDE_PROJECT_DIR )}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 12 | ▶ | my $config_dir = _truthy( $ENV{CLAUDE_CONFIG_DIR} ) ? decode_utf8_lossy( $ENV{CLAUDE_CONFIG_DIR} ) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 12 | ▶ | my %ctx = ( | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$config_dir // path_join($home, ".claude")
MC/DC0%0/2
$config_dir // path_join($home, ".claude")
$config_dir
path_join($home, ".claude")
Truth table33%1/3
A // B
A= $config_dirB= path_join($home, ".claude")
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | home => $home, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | project_dir => $project_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | claude_config_dir => $config_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | state_root => path_join( $config_dir // path_join( $home, '.claude' ), 'skilletor' ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | self_command => self_command(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 12 | ▶ | $ctx{harness} = $harness if defined $harness && ( $harness eq 'codex' || $harness eq 'hermes' ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
defined $harness and $harness eq "codex" || $harness eq "hermes"
$harness eq "codex" or $harness eq "hermes"
MC/DC0%0/3
defined $harness and $harness eq "codex" || $harness eq "hermes"
defined $harness
$harness eq "codex"
$harness eq "hermes"
Truth table25%1/4
A and B or C
A= defined $harnessB= $harness eq "codex"C= $harness eq "hermes"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 12 | require Skilletor::Hooks; | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 12 | return Skilletor::Hooks::run_hook( $event, $input, \%ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 90 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 90 | my ( @argv ) = map { _decode($_) } @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Argument hygiene (spec §7): --version only first, --help anywhere and alone. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 90 | ▶ | if ( @argv && ( $argv[0] eq '--version' || $argv[0] eq '-v' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@argv and $argv[0] eq "--version" || $argv[0] eq "-v"
$argv[0] eq "--version" or $argv[0] eq "-v"
MC/DC100%3/3
@argv and $argv[0] eq "--version" || $argv[0] eq "-v"
@argv
$argv[0] eq "--version"
$argv[0] eq "-v"
Truth table100%4/4
A and B or C
A= @argvB= $argv[0] eq "--version"C= $argv[0] eq "-v"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 5 | _write( \*STDOUT, $VERSION."\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 5 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 85 | ▶ | if ( !@argv || grep { $_ eq '--help' || $_ eq '-h' } @argv ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not @argv or grep {$_ eq "--help" or $_ eq "-h";} @argv
$_ eq '--help' || $_ eq '-h'
MC/DC100%2/2
not @argv or grep {$_ eq "--help" or $_ eq "-h";} @argv
not @argv
grep {$_ eq "--help" or $_ eq "-h";} @argv
MC/DC100%2/2
$_ eq '--help' || $_ eq '-h'
$_ eq '--help'
$_ eq '-h'
Truth table100%3/3
not(A) or B
A= not @argvB= grep {$_ eq "--help" or $_ eq "-h";} @argv
Truth table100%3/3
A || B
A= $_ eq '--help'B= $_ eq '-h'
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 12 | _write( \*STDOUT, USAGE ); # no command has its own help yet | |||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 12 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 73 | my $cmd = $argv[0]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 73 | ▶ | if ( $cmd =~ /\A-/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | _print_lines( \*STDERR, "skilletor: unknown option: $cmd (run skilletor --help)" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 72 | my $flags = parse_flags( @argv[ 1 .. $#argv ] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 479 | # Ahead of every check (k164): a hook never fails on its arguments, and it takes its project | ||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # from its environment or input, not from the process cwd – which may be gone. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 72 | ▶ | return _hook( @{ $flags->{rest} } ) if $cmd eq 'hook'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 58 | my $unknown = unknown_option( $cmd, $flags ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 58 | ▶ | if ( defined $unknown ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 16 | ▶ | my $name = $cmd eq 'source' && exists $ACCEPTED{ _source_key($flags) } ? _source_key($flags) : $cmd; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cmd eq "source" and exists $ACCEPTED{_source_key($flags)}
MC/DC50%1/2
$cmd eq "source" and exists $ACCEPTED{_source_key($flags)}
$cmd eq "source"
exists $ACCEPTED{_source_key($flags)}
Truth table66%2/3
A and B
A= $cmd eq "source"B= exists $ACCEPTED{_source_key($flags)}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 16 | _print_lines( \*STDERR, "skilletor: unknown option for $name: $unknown (run skilletor --help)" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 16 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 42 | my $scope = $flags->{scope}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 42 | ▶ | if ( !defined $scope || !grep { $scope eq $_ } qw( user project all ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $scope and grep {$scope eq $_;} "user", "project", "all"
MC/DC100%2/2
defined $scope and grep {$scope eq $_;} "user", "project", "all"
defined $scope
grep {$scope eq $_;} "user", "project", "all"
Truth table100%3/3
A and B
A= defined $scopeB= grep {$scope eq $_;} "user", "project", "all"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 2 | ▶ | _print_lines( \*STDERR, 'skilletor: invalid --scope: '.( $scope // 'undefined' ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$scope // "undefined"
MC/DC100%1/1
$scope // "undefined"
$scope
Truth table100%2/2
A
A= $scope
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 40 | my $code; | |||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 40 | ▶ | return $code if eval { $code = _dispatch( $cmd, $flags ); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 6 | _print_text( \*STDERR, 'skilletor: '._message($@) ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 40 | ▶ | sub _dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=18 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 40 | my ( $cmd, $flags ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 40 | my @rest = @{ $flags->{rest} }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 40 | ▶ | my $given = sub { defined $_[0] && length $_[0] }; # JavaScript's truthiness of a string | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 40 | ▶ | return _sync($flags) if $cmd eq 'sync'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 35 | ▶ | return _check($flags) if $cmd eq 'check'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 35 | ▶ | return _status($flags) if $cmd eq 'status'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 33 | ▶ | return _available($flags) if $cmd eq 'available'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 32 | ▶ | if ( $cmd eq 'add' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 4 | ▶ | return _usage_error('skilletor: add needs a source spec') unless @rest; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | return _add($flags); | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 28 | ▶ | if ( $cmd eq 'source' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 5 | ▶ | my $sub = $rest[0] // ''; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rest[0] // ""
MC/DC100%1/1
$rest[0] // ""
$rest[0]
Truth table100%2/2
A
A= $rest[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 5 | ▶ | return _source_list($flags) if $sub eq 'list'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 4 | ▶ | if ( $sub eq 'remove' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | ▶ | return _usage_error('skilletor: source remove needs a name') unless $given->( $rest[1] ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | return _source_remove( $flags, $rest[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | return _usage_error('skilletor: usage: source list | source remove <name>'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 23 | ▶ | if ( $cmd eq 'install' || $cmd eq 'uninstall' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$cmd eq "install" or $cmd eq "uninstall"
MC/DC100%2/2
$cmd eq "install" or $cmd eq "uninstall"
$cmd eq "install"
$cmd eq "uninstall"
Truth table100%3/3
A or B
A= $cmd eq "install"B= $cmd eq "uninstall"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 18 | ▶ | return _usage_error("skilletor: $cmd needs at least one item") unless @rest; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 12 | ▶ | return $cmd eq 'install' ? _install($flags) : _uninstall($flags); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 5 | ▶ | if ( $cmd eq 'trust' ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 3 | ▶ | return _usage_error('skilletor: trust needs a source name') unless $given->( $rest[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | return _trust( $flags, $rest[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 2 | _print_lines( \*STDERR, "skilletor: unknown command: $cmd" ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 2 | return 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 232 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||