| 1 | package Tree::Shell::Commands; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 4 | 1 | our $DATE = '2020-02-13'; # DATE | |||||||||||||||||||||||||||||||
| 5 | 1 | our $DIST = 'Tree-Shell'; # DIST | |||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.001'; # VERSION | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Path::Naive qw(); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | our %SPEC; | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 1 | $SPEC{':package'} = { | |||||||||||||||||||||||||||||||
| 18 | v => 1.1, | ||||||||||||||||||||||||||||||||
| 19 | summary => 'treesh commands', | ||||||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | our $complete_path = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 23 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 24 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | my $word0 = $args{word}; | |||||||||||||||||||||||||||||||
| 27 | 0 | my ($dir, $word) = $word0 =~ m!(.*/)?(.*)!; | |||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $dir //= ""; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$dir //= ""
MC/DC0%0/1
$dir //= ""
$dir
Truth table0%0/2
A
A= $dir
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return {message=>"No current object, please load some objects first"} unless $obj; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | my $cwd = $obj->{fs}->cwd; | |||||||||||||||||||||||||||||||
| 34 | my @entries = $obj->{fs}->ls( | ||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | length($dir) ? Path::Naive::concat_and_normalize_path($cwd, $dir)."/*" : undef); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | [map {(length($dir) ? $dir : "") . "$_->{name}/"} @entries]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 1 | }; | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my $complete_setting_name = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 42 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 0 | [keys %{ $shell->known_settings }]; | |||||||||||||||||||||||||||||||
| 45 | 1 | }; | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | our $complete_object_name = sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 48 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 49 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 0 | [keys %{ $shell->state('objects') }]; | |||||||||||||||||||||||||||||||
| 52 | 1 | }; | |||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | 1 | my %arg0_object = ( | |||||||||||||||||||||||||||||||
| 55 | object => { | ||||||||||||||||||||||||||||||||
| 56 | schema => ['str*', match=>qr/\A\w+\z/], | ||||||||||||||||||||||||||||||||
| 57 | completion => $complete_object_name, | ||||||||||||||||||||||||||||||||
| 58 | req => 1, | ||||||||||||||||||||||||||||||||
| 59 | pos => 0, | ||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 1 | my %argopt_object = ( | |||||||||||||||||||||||||||||||
| 64 | object => { | ||||||||||||||||||||||||||||||||
| 65 | schema => ['str*', match=>qr/\A\w+\z/], | ||||||||||||||||||||||||||||||||
| 66 | cmdline_aliases => {o=>{}}, | ||||||||||||||||||||||||||||||||
| 67 | completion => $complete_object_name, | ||||||||||||||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 1 | my %arg0_path = ( | |||||||||||||||||||||||||||||||
| 72 | path => { | ||||||||||||||||||||||||||||||||
| 73 | summary => 'Path', | ||||||||||||||||||||||||||||||||
| 74 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 75 | req => 1, | ||||||||||||||||||||||||||||||||
| 76 | pos => 0, | ||||||||||||||||||||||||||||||||
| 77 | completion => $complete_path, | ||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 1 | my %arg0_paths = ( | |||||||||||||||||||||||||||||||
| 82 | paths => { | ||||||||||||||||||||||||||||||||
| 83 | summary => 'Paths', | ||||||||||||||||||||||||||||||||
| 84 | schema => ['array*', of=>'str*'], | ||||||||||||||||||||||||||||||||
| 85 | req => 1, | ||||||||||||||||||||||||||||||||
| 86 | pos => 0, | ||||||||||||||||||||||||||||||||
| 87 | slurpy => 1, | ||||||||||||||||||||||||||||||||
| 88 | element_completion => $complete_path, | ||||||||||||||||||||||||||||||||
| 89 | }, | ||||||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 1 | my %argopt0_path = ( | |||||||||||||||||||||||||||||||
| 93 | path => { | ||||||||||||||||||||||||||||||||
| 94 | summary => 'Path to node', | ||||||||||||||||||||||||||||||||
| 95 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 96 | pos => 0, | ||||||||||||||||||||||||||||||||
| 97 | completion => $complete_path, | ||||||||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 1 | my @drivers = qw(json yaml org); | |||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | $SPEC{loadobj} = { | ||||||||||||||||||||||||||||||||
| 104 | v => 1.1, | ||||||||||||||||||||||||||||||||
| 105 | summary => 'Load tree object', | ||||||||||||||||||||||||||||||||
| 106 | description => <<'_', | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | _ | ||||||||||||||||||||||||||||||||
| 109 | args => { | ||||||||||||||||||||||||||||||||
| 110 | as => { | ||||||||||||||||||||||||||||||||
| 111 | schema => ['str*', {match => qr/\A\w+\z/}], | ||||||||||||||||||||||||||||||||
| 112 | pos => 0, | ||||||||||||||||||||||||||||||||
| 113 | req => 1, | ||||||||||||||||||||||||||||||||
| 114 | }, | ||||||||||||||||||||||||||||||||
| 115 | driver => { | ||||||||||||||||||||||||||||||||
| 116 | schema => ['str*', {in=>\@drivers}], | ||||||||||||||||||||||||||||||||
| 117 | pos => 1, | ||||||||||||||||||||||||||||||||
| 118 | req => 1, | ||||||||||||||||||||||||||||||||
| 119 | }, | ||||||||||||||||||||||||||||||||
| 120 | source => { | ||||||||||||||||||||||||||||||||
| 121 | schema => ['pathname*'], | ||||||||||||||||||||||||||||||||
| 122 | pos => 2, | ||||||||||||||||||||||||||||||||
| 123 | req => 1, | ||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | completion => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 125 | 0 | require Complete::File; | |||||||||||||||||||||||||||||||
| 126 | 0 | Complete::File::complete_file(@_); | |||||||||||||||||||||||||||||||
| 127 | }, | ||||||||||||||||||||||||||||||||
| 128 | }, | ||||||||||||||||||||||||||||||||
| 129 | 1 | opts => { | |||||||||||||||||||||||||||||||
| 130 | 'x.name.is_plural' => 1, | ||||||||||||||||||||||||||||||||
| 131 | 'x.name.singular' => 'opt', | ||||||||||||||||||||||||||||||||
| 132 | schema => ['hash*', {of=>'str*'}], | ||||||||||||||||||||||||||||||||
| 133 | }, | ||||||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||||||
| 135 | }; | ||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub loadobj { | ||||||||||||||||||||||||||||||
|
Subroutine
loadobj: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 137 | 0 | require File::Slurper::Dash; | |||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 140 | 0 | my $as = $args{as}; | |||||||||||||||||||||||||||||||
| 141 | 0 | my $driver = $args{driver}; | |||||||||||||||||||||||||||||||
| 142 | 0 | my $source = $args{source}; | |||||||||||||||||||||||||||||||
| 143 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if ($shell->state('objects')->{$as}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | 0 | return [412, "Object with named '$as' already loaded, perhaps choose another name?"]; | |||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 0 | my $fs; | |||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($driver eq 'json') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 151 | 0 | return [501, "Not implemented"]; | |||||||||||||||||||||||||||||||
| 152 | #require Data::CSel::WrapStruct; | ||||||||||||||||||||||||||||||||
| 153 | #require JSON::MaybeXS; | ||||||||||||||||||||||||||||||||
| 154 | #my $json = JSON::MaybeXS->new(allow_nonref=>1, canonical=>1); | ||||||||||||||||||||||||||||||||
| 155 | #my $data = $json->decode(File::Slurper::Dash::read_text($source)); | ||||||||||||||||||||||||||||||||
| 156 | #$tree = Data::CSel::WrapStruct::wrap_struct($data); | ||||||||||||||||||||||||||||||||
| 157 | } elsif ($driver eq 'yaml') { | ||||||||||||||||||||||||||||||||
| 158 | 0 | return [501, "Not implemented"]; | |||||||||||||||||||||||||||||||
| 159 | #require Data::CSel::WrapStruct; | ||||||||||||||||||||||||||||||||
| 160 | #require YAML::XS; | ||||||||||||||||||||||||||||||||
| 161 | #my $data = YAML::XS::Load(File::Slurper::Dash::read_text($source)); | ||||||||||||||||||||||||||||||||
| 162 | #my $tree = Data::CSel::WrapStruct::wrap_struct($data); | ||||||||||||||||||||||||||||||||
| 163 | } elsif ($driver eq 'org') { | ||||||||||||||||||||||||||||||||
| 164 | 0 | require Tree::FSMethods::Org; | |||||||||||||||||||||||||||||||
| 165 | 0 | eval { $fs = Tree::FSMethods::Org->new(org_file => $source) }; | |||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return [500, "Can't load org file: $@"] if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||
| 168 | 0 | return [500, "Unknown driver '$driver', known drivers: ".join(", ", @drivers)]; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | $shell->state('objects')->{$as} = { | |||||||||||||||||||||||||||||||
| 172 | driver => $driver, | ||||||||||||||||||||||||||||||||
| 173 | source => $source, | ||||||||||||||||||||||||||||||||
| 174 | fs => $fs, | ||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $shell->state('curobj', $as) unless defined $shell->state('curobj'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 177 | 0 | return [200, "OK"]; | |||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | $SPEC{objects} = { | ||||||||||||||||||||||||||||||||
| 181 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 182 | summary => 'List loaded objects', | ||||||||||||||||||||||||||||||||
| 183 | description => <<'_', | ||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||
| 185 | _ | ||||||||||||||||||||||||||||||||
| 186 | args => { | ||||||||||||||||||||||||||||||||
| 187 | }, | ||||||||||||||||||||||||||||||||
| 188 | }; | ||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub objects { | ||||||||||||||||||||||||||||||
|
Subroutine
objects: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 190 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 191 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | 0 | my $objects = $shell->state('objects'); | |||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | my $curobj = $shell->state('curobj') // ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$shell->state("curobj") // ""
MC/DC0%0/1
$shell->state("curobj") // ""
$shell->state("curobj")
Truth table0%0/2
A
A= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 195 | 0 | my @rows; | |||||||||||||||||||||||||||||||
| 196 | 0 | for my $name (sort keys %$objects) { | |||||||||||||||||||||||||||||||
| 197 | push @rows, { | ||||||||||||||||||||||||||||||||
| 198 | name => $name, | ||||||||||||||||||||||||||||||||
| 199 | driver => $objects->{$name}{driver}, | ||||||||||||||||||||||||||||||||
| 200 | source => $objects->{$name}{source}, | ||||||||||||||||||||||||||||||||
| 201 | active => $name eq $curobj ? 1:0, | ||||||||||||||||||||||||||||||||
| 202 | cwd => $objects->{$name}{fs}->cwd, | ||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | 0 | [200, "OK", \@rows, {'table.fields'=>[qw/name driver source active cwd/]}]; | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||
| 208 | $SPEC{setcurobj} = { | ||||||||||||||||||||||||||||||||
| 209 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 210 | summary => 'Set current object', | ||||||||||||||||||||||||||||||||
| 211 | args => { | ||||||||||||||||||||||||||||||||
| 212 | %arg0_object, | ||||||||||||||||||||||||||||||||
| 213 | }, | ||||||||||||||||||||||||||||||||
| 214 | }; | ||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub setcurobj { | ||||||||||||||||||||||||||||||
|
Subroutine
setcurobj: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 216 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 217 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | 0 | my $objects = $shell->state('objects'); | |||||||||||||||||||||||||||||||
| 220 | $objects->{ $args{object} } | ||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | or return [404, "No such object '$args{object}'"]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 222 | 0 | $shell->state('curobj', $args{object}); | |||||||||||||||||||||||||||||||
| 223 | 0 | [200]; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | $SPEC{cat} = { | ||||||||||||||||||||||||||||||||
| 227 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 228 | summary => 'Print node as string', | ||||||||||||||||||||||||||||||||
| 229 | args => { | ||||||||||||||||||||||||||||||||
| 230 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 231 | %arg0_path, | ||||||||||||||||||||||||||||||||
| 232 | }, | ||||||||||||||||||||||||||||||||
| 233 | }; | ||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | sub cat { | ||||||||||||||||||||||||||||||
|
Subroutine
cat: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 235 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 236 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 241 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | 0 | my $node; | |||||||||||||||||||||||||||||||
| 245 | 0 | eval { | |||||||||||||||||||||||||||||||
| 246 | 0 | $node = $obj->{fs}->get($args{path}); | |||||||||||||||||||||||||||||||
| 247 | }; | ||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | return [500, "Can't cat: $@"] if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 0 | [200, "OK", $node->as_string]; | |||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||
| 253 | $SPEC{dumpobj} = { | ||||||||||||||||||||||||||||||||
| 254 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 255 | summary => 'Dump a loaded object', | ||||||||||||||||||||||||||||||||
| 256 | description => <<'_', | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | _ | ||||||||||||||||||||||||||||||||
| 259 | args => { | ||||||||||||||||||||||||||||||||
| 260 | name => { | ||||||||||||||||||||||||||||||||
| 261 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 262 | pos => 0, | ||||||||||||||||||||||||||||||||
| 263 | completion => $complete_object_name, | ||||||||||||||||||||||||||||||||
| 264 | }, | ||||||||||||||||||||||||||||||||
| 265 | }, | ||||||||||||||||||||||||||||||||
| 266 | }; | ||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub dumpobj { | ||||||||||||||||||||||||||||||
|
Subroutine
dumpobj: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 268 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 269 | 0 | my $name = $args{name}; | |||||||||||||||||||||||||||||||
| 270 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $name //= $shell->state('curobj'); | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$name //= $shell->state("curobj")
MC/DC0%0/2
$name //= $shell->state("curobj")
$name
$shell->state("curobj")
Truth table0%0/3
A //= B
A= $nameB= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return [412, "Please load an object first"] unless defined $name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | 0 | my $objects = $shell->state('objects'); | |||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return [404, "No object by that name"] unless $objects->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 0 | require Tree::Dump; | |||||||||||||||||||||||||||||||
| 279 | 0 | [200, "OK", Tree::Dump::tdmp($objects->{$name}{fs}{tree}), | |||||||||||||||||||||||||||||||
| 280 | {'cmdline.skip_format'=>1}]; | ||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | $SPEC{ls} = { | ||||||||||||||||||||||||||||||||
| 284 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 285 | summary => 'List children nodes', | ||||||||||||||||||||||||||||||||
| 286 | args => { | ||||||||||||||||||||||||||||||||
| 287 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 288 | long => { | ||||||||||||||||||||||||||||||||
| 289 | summary => 'Long mode (detail=1)', | ||||||||||||||||||||||||||||||||
| 290 | schema => ['true*'], | ||||||||||||||||||||||||||||||||
| 291 | cmdline_aliases => { l => {} }, | ||||||||||||||||||||||||||||||||
| 292 | }, | ||||||||||||||||||||||||||||||||
| 293 | path => { | ||||||||||||||||||||||||||||||||
| 294 | summary => 'Path to node', | ||||||||||||||||||||||||||||||||
| 295 | schema => ['str'], | ||||||||||||||||||||||||||||||||
| 296 | pos => 0, | ||||||||||||||||||||||||||||||||
| 297 | completion => $complete_path, | ||||||||||||||||||||||||||||||||
| 298 | }, | ||||||||||||||||||||||||||||||||
| 299 | all => { | ||||||||||||||||||||||||||||||||
| 300 | summary => 'Does nothing, added only to let you type ls -la', | ||||||||||||||||||||||||||||||||
| 301 | schema => ['bool'], | ||||||||||||||||||||||||||||||||
| 302 | description => <<'_', | ||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||
| 304 | Some of you might type `ls -la` or `ls -al` by muscle memory. So the -a option | ||||||||||||||||||||||||||||||||
| 305 | is added just to allow this to not produce an error :-). | ||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||
| 307 | _ | ||||||||||||||||||||||||||||||||
| 308 | cmdline_aliases => { a=>{} }, | ||||||||||||||||||||||||||||||||
| 309 | }, | ||||||||||||||||||||||||||||||||
| 310 | }, | ||||||||||||||||||||||||||||||||
| 311 | }; | ||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub ls { | ||||||||||||||||||||||||||||||
|
Subroutine
ls: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 313 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 314 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 321 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 0 | my @rows; | |||||||||||||||||||||||||||||||
| 325 | my @entries; | ||||||||||||||||||||||||||||||||
| 326 | 0 | eval { @entries = $obj->{fs}->ls($args{path}) }; | |||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | return [500, "Can't ls: $@"] if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||
| 329 | 0 | for my $entry (@entries) { | |||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | if ($args{long}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 331 | push @rows, { | ||||||||||||||||||||||||||||||||
| 332 | order => $entry->{order}, | ||||||||||||||||||||||||||||||||
| 333 | name => $entry->{name}, | ||||||||||||||||||||||||||||||||
| 334 | 0 | }; | |||||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||||||
| 336 | 0 | push @rows, $entry->{name}; | |||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $resmeta->{'table.fields'} = [qw/order name/] if $args{long}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 341 | 0 | [200, "OK", \@rows, $resmeta]; | |||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | $SPEC{pwd} = { | ||||||||||||||||||||||||||||||||
| 345 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 346 | summary => 'Show current directory of object', | ||||||||||||||||||||||||||||||||
| 347 | args => { | ||||||||||||||||||||||||||||||||
| 348 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 349 | }, | ||||||||||||||||||||||||||||||||
| 350 | }; | ||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub pwd { | ||||||||||||||||||||||||||||||
|
Subroutine
pwd: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 352 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 353 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my $objname = $args{object} // $shell->state('curobj') // ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 356 | 0 | my $obj = $shell->state('objects')->{ $objname }; | |||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 359 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | 0 | return [200, "OK", "$obj->{fs}{_curpath} ($objname)"]; | |||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | $SPEC{cd} = { | ||||||||||||||||||||||||||||||||
| 366 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 367 | summary => "Change directory", | ||||||||||||||||||||||||||||||||
| 368 | args => { | ||||||||||||||||||||||||||||||||
| 369 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 370 | path => { | ||||||||||||||||||||||||||||||||
| 371 | summary => '', | ||||||||||||||||||||||||||||||||
| 372 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 373 | pos => 0, | ||||||||||||||||||||||||||||||||
| 374 | completion => $complete_path, | ||||||||||||||||||||||||||||||||
| 375 | }, | ||||||||||||||||||||||||||||||||
| 376 | }, | ||||||||||||||||||||||||||||||||
| 377 | }; | ||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | sub cd { | ||||||||||||||||||||||||||||||
|
Subroutine
cd: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 379 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 380 | 0 | my $path = $args{path}; | |||||||||||||||||||||||||||||||
| 381 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 386 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 0 | my $cwd = $obj->{fs}->cwd; | |||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if ($path eq '-') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if (defined $obj->{oldcwd}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 392 | 0 | $path = $obj->{oldcwd}; | |||||||||||||||||||||||||||||||
| 393 | } else { | ||||||||||||||||||||||||||||||||
| 394 | 0 | return [412, "Old directory not set yet, cd to some directory first"]; | |||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | 0 | eval { $obj->{fs}->cd($path) }; | |||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 400 | 0 | return [500, "Can't cd: $@"]; | |||||||||||||||||||||||||||||||
| 401 | } else { | ||||||||||||||||||||||||||||||||
| 402 | 0 | $obj->{oldcwd} = $cwd; | |||||||||||||||||||||||||||||||
| 403 | 0 | return [200, "OK"]; | |||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||
| 407 | $SPEC{tree} = { | ||||||||||||||||||||||||||||||||
| 408 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 409 | summary => 'Show filesystem tree', | ||||||||||||||||||||||||||||||||
| 410 | args => { | ||||||||||||||||||||||||||||||||
| 411 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 412 | %argopt0_path, | ||||||||||||||||||||||||||||||||
| 413 | }, | ||||||||||||||||||||||||||||||||
| 414 | }; | ||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub tree { | ||||||||||||||||||||||||||||||
|
Subroutine
tree: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 416 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 417 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||
| 419 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 424 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||
| 427 | 0 | [200, "OK", $obj->{fs}->showtree($args{path})]; | |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | our %args_cp_or_mv = ( | ||||||||||||||||||||||||||||||||
| 431 | src_path => { | ||||||||||||||||||||||||||||||||
| 432 | summary => 'Source path', | ||||||||||||||||||||||||||||||||
| 433 | schema => 'str*', | ||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | completion => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 435 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 436 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | my $obj = $shell->state('objects')->{ $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$shell->state("curobj") // ""
MC/DC0%0/1
$shell->state("curobj") // ""
$shell->state("curobj")
Truth table0%0/2
A
A= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | return [] unless $obj; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 439 | 0 | my $res = $complete_path->(%args); | |||||||||||||||||||||||||||||||
| 440 | 0 | $res; | |||||||||||||||||||||||||||||||
| 441 | }, | ||||||||||||||||||||||||||||||||
| 442 | req => 1, | ||||||||||||||||||||||||||||||||
| 443 | pos => 0, | ||||||||||||||||||||||||||||||||
| 444 | }, | ||||||||||||||||||||||||||||||||
| 445 | target_object => { | ||||||||||||||||||||||||||||||||
| 446 | summary => 'Target object name', | ||||||||||||||||||||||||||||||||
| 447 | schema => ['str*', match=>qr/\A\w+\z/], | ||||||||||||||||||||||||||||||||
| 448 | completion => $complete_object_name, | ||||||||||||||||||||||||||||||||
| 449 | }, | ||||||||||||||||||||||||||||||||
| 450 | target_path => { | ||||||||||||||||||||||||||||||||
| 451 | summary => 'Target path', | ||||||||||||||||||||||||||||||||
| 452 | schema => 'str*', | ||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | completion => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 454 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 455 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 456 | 0 | my $target_object = $args{args}{target_object}; | |||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | my $obj = $shell->state('objects')->{ $target_object // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($target_object // $shell->state("curobj")) // ""
$target_object // $shell->state("curobj")
MC/DC0%0/2
($target_object // $shell->state("curobj")) // ""
$target_object
$shell->state("curobj")
Truth table0%0/3
A // B
A= $target_objectB= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | return [] unless $obj; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 459 | 0 | my $save_curobj = $shell->state('curobj'); | |||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | $shell->state('curobj', $target_object) if defined $target_object; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 461 | 0 | my $res = $complete_path->(%args); | |||||||||||||||||||||||||||||||
| 462 | 0 | $shell->state('curobj', $save_curobj); | |||||||||||||||||||||||||||||||
| 463 | 0 | $res; | |||||||||||||||||||||||||||||||
| 464 | }, | ||||||||||||||||||||||||||||||||
| 465 | 1 | req => 1, | |||||||||||||||||||||||||||||||
| 466 | pos => 1, | ||||||||||||||||||||||||||||||||
| 467 | }, | ||||||||||||||||||||||||||||||||
| 468 | ); | ||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | sub _cp_or_mv { | ||||||||||||||||||||||||||||||
|
Subroutine
_cp_or_mv: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 471 | 0 | my $which = shift; | |||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 474 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | my $src_obj = $shell->state('objects')->{ $shell->state('curobj') // '' } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$shell->state("curobj") // ""
MC/DC0%0/1
$shell->state("curobj") // ""
$shell->state("curobj")
Truth table0%0/2
A
A= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 477 | or return [412, "No object loaded, please load an object first"]; | ||||||||||||||||||||||||||||||||
| 478 | 0 | ▶ | my $target_obj = $shell->state('objects')->{ $args{target_object} // $shell->state('curobj') // '' } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
($args{"target_object"} // $shell->state("curobj")) // ""
$args{"target_object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"target_object"} // $shell->state("curobj")) // ""
$args{"target_object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"target_object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 479 | or return [412, "No such target object '$args{target_object}'"]; | ||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | 0 | eval { | |||||||||||||||||||||||||||||||
| 482 | 0 | local $src_obj->{fs}{tree2} = $target_obj->{fs}{tree}; | |||||||||||||||||||||||||||||||
| 483 | 0 | local $src_obj->{fs}{_curnode2} = $target_obj->{fs}{_curnode}; | |||||||||||||||||||||||||||||||
| 484 | 0 | local $src_obj->{fs}{_curpath2} = $target_obj->{fs}{_curpath}; | |||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||
| 486 | 0 | $src_obj->{fs}->$which($args{src_path}, $args{target_path}); | |||||||||||||||||||||||||||||||
| 487 | }; | ||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | return [500, "Can't $which: $@"] if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 489 | 0 | [200]; | |||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||
| 492 | $SPEC{cp} = { | ||||||||||||||||||||||||||||||||
| 493 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 494 | summary => 'Copy nodes from one object to another', | ||||||||||||||||||||||||||||||||
| 495 | args => { | ||||||||||||||||||||||||||||||||
| 496 | %args_cp_or_mv, | ||||||||||||||||||||||||||||||||
| 497 | }, | ||||||||||||||||||||||||||||||||
| 498 | }; | ||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | sub cp { | ||||||||||||||||||||||||||||||
|
Subroutine
cp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 500 | 0 | _cp_or_mv('cp', @_); | |||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||
| 503 | $SPEC{mv} = { | ||||||||||||||||||||||||||||||||
| 504 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 505 | summary => 'Move nodes from one object to another', | ||||||||||||||||||||||||||||||||
| 506 | args => { | ||||||||||||||||||||||||||||||||
| 507 | %args_cp_or_mv, | ||||||||||||||||||||||||||||||||
| 508 | }, | ||||||||||||||||||||||||||||||||
| 509 | }; | ||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub mv { | ||||||||||||||||||||||||||||||
|
Subroutine
mv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 511 | 0 | _cp_or_mv('mv', @_); | |||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | $SPEC{rm} = { | ||||||||||||||||||||||||||||||||
| 515 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 516 | summary => 'Remove nodes', | ||||||||||||||||||||||||||||||||
| 517 | args => { | ||||||||||||||||||||||||||||||||
| 518 | %arg0_path, | ||||||||||||||||||||||||||||||||
| 519 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 520 | }, | ||||||||||||||||||||||||||||||||
| 521 | }; | ||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | sub rm { | ||||||||||||||||||||||||||||||
|
Subroutine
rm: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 523 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 524 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||
| 526 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 530 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 531 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||
| 534 | 0 | eval { | |||||||||||||||||||||||||||||||
| 535 | 0 | $obj->{fs}->rm($args{path}); | |||||||||||||||||||||||||||||||
| 536 | }; | ||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | return [500, "Can't rm: $@"] if $@; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||
| 539 | 0 | [200]; | |||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||
| 542 | $SPEC{mkdir} = { | ||||||||||||||||||||||||||||||||
| 543 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 544 | summary => 'Create an empty directory', | ||||||||||||||||||||||||||||||||
| 545 | args => { | ||||||||||||||||||||||||||||||||
| 546 | %arg0_paths, | ||||||||||||||||||||||||||||||||
| 547 | %argopt_object, | ||||||||||||||||||||||||||||||||
| 548 | parents => { | ||||||||||||||||||||||||||||||||
| 549 | schema => 'true*', | ||||||||||||||||||||||||||||||||
| 550 | cmdline_aliases => {p=>{}}, | ||||||||||||||||||||||||||||||||
| 551 | }, | ||||||||||||||||||||||||||||||||
| 552 | }, | ||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||
| 554 | 0 | ▶ | sub mkdir { | ||||||||||||||||||||||||||||||
|
Subroutine
mkdir: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 555 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 556 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||
| 558 | 0 | my $resmeta = {}; | |||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | my $obj = $shell->state('objects')->{ $args{object} // $shell->state('curobj') // '' }; | ||||||||||||||||||||||||||||||
|
Condition0%0/5
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"} // $shell->state("curobj")
MC/DC0%0/2
($args{"object"} // $shell->state("curobj")) // ""
$args{"object"}
$shell->state("curobj")
Truth table0%0/3
A // B
A= $args{"object"}B= $shell->state("curobj")
| |||||||||||||||||||||||||||||||||
| 561 | 0 | ▶ | unless ($obj) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | return [412, "No such object '$args{object}'"] if defined $args{object}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 563 | 0 | return [412, "No loaded objects, load some first using 'loadobj'"]; | |||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||
| 566 | 0 | my %opts; | |||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | $opts{parents} = 1 if $args{parents}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||
| 569 | 0 | my $has_error; | |||||||||||||||||||||||||||||||
| 570 | 0 | for my $path (@{ $args{paths} }) { | |||||||||||||||||||||||||||||||
| 571 | 0 | eval { $obj->{fs}->mkdir(\%opts, $path) }; | |||||||||||||||||||||||||||||||
| 572 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 573 | 0 | warn "Can't mkdir $path: $@\n"; | |||||||||||||||||||||||||||||||
| 574 | 0 | $has_error++; | |||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||
| 578 | 0 | [200]; | |||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||
| 581 | $SPEC{set} = { | ||||||||||||||||||||||||||||||||
| 582 | v => 1.1, | ||||||||||||||||||||||||||||||||
| 583 | summary => "List or set setting", | ||||||||||||||||||||||||||||||||
| 584 | args => { | ||||||||||||||||||||||||||||||||
| 585 | name => { | ||||||||||||||||||||||||||||||||
| 586 | summary => '', | ||||||||||||||||||||||||||||||||
| 587 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 588 | pos => 0, | ||||||||||||||||||||||||||||||||
| 589 | # we use custom completion because the list of known settings must | ||||||||||||||||||||||||||||||||
| 590 | # be retrieved through the shell object | ||||||||||||||||||||||||||||||||
| 591 | completion => $complete_setting_name, | ||||||||||||||||||||||||||||||||
| 592 | }, | ||||||||||||||||||||||||||||||||
| 593 | value => { | ||||||||||||||||||||||||||||||||
| 594 | summary => '', | ||||||||||||||||||||||||||||||||
| 595 | schema => ['any'], | ||||||||||||||||||||||||||||||||
| 596 | pos => 1, | ||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | completion => sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 598 | 0 | require Perinci::Sub::Complete; | |||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||
| 600 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 601 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 602 | 0 | my $args = $args{args}; | |||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | return [] unless $args->{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 604 | 0 | my $setting = $shell->known_settings->{ $args->{name} }; | |||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | return [] unless $setting; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||
| 607 | # a hack, construct a throwaway meta and using that to complete | ||||||||||||||||||||||||||||||||
| 608 | # setting argument as function argument | ||||||||||||||||||||||||||||||||
| 609 | Perinci::Sub::Complete::complete_arg_val( | ||||||||||||||||||||||||||||||||
| 610 | arg=>'foo', | ||||||||||||||||||||||||||||||||
| 611 | meta=>{v=>1.1, args=>{foo=>{schema=>$setting->{schema}}}}, | ||||||||||||||||||||||||||||||||
| 612 | 0 | ); | |||||||||||||||||||||||||||||||
| 613 | }, | ||||||||||||||||||||||||||||||||
| 614 | }, | ||||||||||||||||||||||||||||||||
| 615 | }, | ||||||||||||||||||||||||||||||||
| 616 | 1 | }; | |||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | sub set { | ||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 618 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 619 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||
| 621 | 0 | my $name = $args{name}; | |||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | if (exists $args{value}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 624 | # set setting | ||||||||||||||||||||||||||||||||
| 625 | return [400, "Unknown setting, use 'set' to list all known settings"] | ||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | unless exists $shell->known_settings->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 627 | 0 | $shell->setting($name, $args{value}); | |||||||||||||||||||||||||||||||
| 628 | 0 | [200, "OK"]; | |||||||||||||||||||||||||||||||
| 629 | } else { | ||||||||||||||||||||||||||||||||
| 630 | # list settings | ||||||||||||||||||||||||||||||||
| 631 | 0 | my $res = []; | |||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if (defined $name) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 633 | return [400,"Unknown setting, use 'set' to list all known settings"] | ||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | unless exists $shell->known_settings->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||
| 636 | 0 | for (sort keys %{ $shell->known_settings }) { | |||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | next if defined($name) && $_ ne $name; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $name and $_ ne $name
MC/DC0%0/2
defined $name and $_ ne $name
defined $name
$_ ne $name
Truth table0%0/3
A and B
A= defined $nameB= $_ ne $name
| |||||||||||||||||||||||||||||||||
| 638 | push @$res, { | ||||||||||||||||||||||||||||||||
| 639 | name => $_, | ||||||||||||||||||||||||||||||||
| 640 | summary => $shell->known_settings->{$_}{summary}, | ||||||||||||||||||||||||||||||||
| 641 | value => $shell->{_settings}{$_}, | ||||||||||||||||||||||||||||||||
| 642 | default => $shell->known_settings->{$_}{schema}[1]{default}, | ||||||||||||||||||||||||||||||||
| 643 | 0 | }; | |||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||
| 645 | 0 | [200, "OK", $res, {'table.fields' => [qw/name summary value default/]}]; | |||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||
| 649 | $SPEC{unset} = { | ||||||||||||||||||||||||||||||||
| 650 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 651 | summary => "Unset a setting", | ||||||||||||||||||||||||||||||||
| 652 | args => { | ||||||||||||||||||||||||||||||||
| 653 | name => { | ||||||||||||||||||||||||||||||||
| 654 | summary => '', | ||||||||||||||||||||||||||||||||
| 655 | schema => ['str*'], | ||||||||||||||||||||||||||||||||
| 656 | req => 1, | ||||||||||||||||||||||||||||||||
| 657 | pos => 0, | ||||||||||||||||||||||||||||||||
| 658 | completion => $complete_setting_name, | ||||||||||||||||||||||||||||||||
| 659 | }, | ||||||||||||||||||||||||||||||||
| 660 | }, | ||||||||||||||||||||||||||||||||
| 661 | }; | ||||||||||||||||||||||||||||||||
| 662 | 0 | ▶ | sub unset { | ||||||||||||||||||||||||||||||
|
Subroutine
unset: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 663 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 664 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||
| 666 | 0 | my $name = $args{name}; | |||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||
| 668 | return [400, "Unknown setting, use 'set' to list all known settings"] | ||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | unless exists $shell->known_settings->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 670 | 0 | delete $shell->{_settings}{$name}; | |||||||||||||||||||||||||||||||
| 671 | 0 | [200, "OK"]; | |||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||
| 674 | $SPEC{history} = { | ||||||||||||||||||||||||||||||||
| 675 | 1 | v => 1.1, | |||||||||||||||||||||||||||||||
| 676 | summary => 'Show command-line history', | ||||||||||||||||||||||||||||||||
| 677 | args => { | ||||||||||||||||||||||||||||||||
| 678 | append => { | ||||||||||||||||||||||||||||||||
| 679 | summary => "Append current session's history to history file", | ||||||||||||||||||||||||||||||||
| 680 | schema => 'bool', | ||||||||||||||||||||||||||||||||
| 681 | cmdline_aliases => { a=>{} }, | ||||||||||||||||||||||||||||||||
| 682 | }, | ||||||||||||||||||||||||||||||||
| 683 | read => { | ||||||||||||||||||||||||||||||||
| 684 | summary => '(Re-)read history from file', | ||||||||||||||||||||||||||||||||
| 685 | schema => 'bool', | ||||||||||||||||||||||||||||||||
| 686 | cmdline_aliases => { r=>{} }, | ||||||||||||||||||||||||||||||||
| 687 | }, | ||||||||||||||||||||||||||||||||
| 688 | clear => { | ||||||||||||||||||||||||||||||||
| 689 | summary => 'Clear history', | ||||||||||||||||||||||||||||||||
| 690 | schema => 'bool', | ||||||||||||||||||||||||||||||||
| 691 | cmdline_aliases => { c=>{} }, | ||||||||||||||||||||||||||||||||
| 692 | }, | ||||||||||||||||||||||||||||||||
| 693 | }, | ||||||||||||||||||||||||||||||||
| 694 | }; | ||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | sub history { | ||||||||||||||||||||||||||||||
|
Subroutine
history: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 696 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||
| 697 | 0 | my $shell = $args{-shell}; | |||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | if ($args{add}) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 700 | 0 | $shell->save_history; | |||||||||||||||||||||||||||||||
| 701 | 0 | return [200, "OK"]; | |||||||||||||||||||||||||||||||
| 702 | } elsif ($args{read}) { | ||||||||||||||||||||||||||||||||
| 703 | 0 | $shell->load_history; | |||||||||||||||||||||||||||||||
| 704 | 0 | return [200, "OK"]; | |||||||||||||||||||||||||||||||
| 705 | } elsif ($args{clear}) { | ||||||||||||||||||||||||||||||||
| 706 | 0 | $shell->clear_history; | |||||||||||||||||||||||||||||||
| 707 | 0 | return [200, "OK"]; | |||||||||||||||||||||||||||||||
| 708 | } else { | ||||||||||||||||||||||||||||||||
| 709 | 0 | my @history; | |||||||||||||||||||||||||||||||
| 710 | 0 | ▶ | if ($shell->{term}->Features->{getHistory}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 711 | 0 | @history = grep { length } $shell->{term}->GetHistory; | |||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||
| 713 | 0 | return [200, "OK", \@history, | |||||||||||||||||||||||||||||||
| 714 | {"x.app.riap.default_format"=>"text-simple"}]; | ||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||
| 718 | 1 | 1; | |||||||||||||||||||||||||||||||
| 719 | # ABSTRACT: treesh commands | ||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||
| 721 | __END__ | ||||||||||||||||||||||||||||||||