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