File Coverage

blib/lib/App/Rakubrew/Shell/Cmd.pm
Criterion Covered Total %
statement 29 51 56.8
branch 1 6 16.6
condition 0 6 0.0
subroutine 10 16 62.5
pod 0 7 0.0
total 40 86 46.5


line stmt bran cond sub pod time code
1             package App::Rakubrew::Shell::Cmd;
2 1     1   9 use App::Rakubrew::Shell;
  1         3  
  1         46  
3             our @ISA = "App::Rakubrew::Shell";
4 1     1   5 use strict;
  1         2  
  1         33  
5 1     1   5 use warnings;
  1         2  
  1         26  
6 1     1   24 use 5.010;
  1         4  
7              
8 1     1   6 use App::Rakubrew::Variables;
  1         3  
  1         151  
9 1     1   7 use App::Rakubrew::Tools;
  1         2  
  1         75  
10 1     1   6 use App::Rakubrew::VersionHandling;
  1         2  
  1         123  
11 1     1   6 use App::Rakubrew::Build;
  1         2  
  1         39  
12 1     1   6 use App::Rakubrew::Config;
  1         2  
  1         521  
13              
14             # https://superuser.com/a/302553
15              
16             sub supports_hooking {
17 0     0 0 0 my $self = shift;
18 0         0 1;
19             }
20              
21             sub install_note {
22             # The autorun guard to prevent endless loops is based on this StackOverflow
23             # answer: https://stackoverflow.com/a/57451662/1975049
24              
25 1     1 0 317 my $text = <
26             To load $brew_name in CMD automatically you have to do two things:
27              
28             1. Check that you don't already have a CMD autorun script set.
29              
30             reg query "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun
31              
32             If you don't have an autorun script set (the above command returns an error) you can set one using:
33              
34             reg add "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d \\""\%"USERPROFILE"\%\\Documents\\CMD_profile.cmd"\\" /f
35              
36             2. Add the following code to the end of the autorun script you linked in step 1:
37              
38             \@echo off
39             setlocal EnableDelayedExpansion
40             set "cmd=!cmdcmdline!"
41             if "!cmd!" == "!cmd:/=!" (
42             endlocal
43             FOR /f "delims=" \%\%i in ('"$brew_exec" init Cmd') do \@\%\%i
44             )
45              
46             You can easily do that from a CMD prompt using the following command:
47              
48             (
49             echo \@echo off
50             echo setlocal EnableDelayedExpansion
51             echo set "cmd=!cmdcmdline!"
52             echo if "!cmd!" == "!cmd:/=!" ^(
53             echo endlocal
54             echo FOR /f "delims=" \%\%i in ^('"$brew_exec" init Cmd'^) do \@\%\%i
55             echo ^)
56             ) >> "\%USERPROFILE\%\\Documents\\CMD_profile.cmd"
57              
58             If you use a different autorun script location, replace the path in the command above.
59              
60             (Note that the above does *not* enable auto-loading in PowerShell, that needs a
61             separate installation procedure. Call `$brew_exec init` in a PowerShell window
62             for respective installation instructions.)
63             EOT
64              
65 1 50       5 if ($prefix =~ / /) {
66 0         0 $text .= <
67              
68             =================================== WARNING ==================================
69              
70             rakubrews home directory is currently
71              
72             $prefix
73              
74             That folder contains spaces. This will break building rakudos as the build
75             system currently doesn't work in such a path. You can work around this problem
76             by changing that folder to a directory without spaces. Do so by putting
77              
78             set RAKUBREW_HOME=/some/folder/without/space/rakubrew
79              
80             in your profile file *before* the other code.
81             EOW
82             }
83 1         18 return $text;
84             }
85              
86             sub get_init_code {
87 0     0 0   my $self = shift;
88 0           my $path = $ENV{PATH};
89 0           $path = $self->clean_path($path);
90 0 0         if (get_brew_mode() eq 'env') {
91 0           my $version = get_global_version();
92 0 0 0       if ($version && $version ne 'system' && !is_version_broken($version)) {
      0        
93 0           $path = join(';', get_bin_paths($version), $path);
94             }
95             }
96             else { # get_brew_mode() eq 'shim'
97 0           $path = join(';', $shim_dir, $path);
98             }
99              
100             # https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/doskey
101             # https://devblogs.microsoft.com/oldnewthing/20120731-00/?p=7003
102             # The command that post_call_eval() returns is always a single line, so we can get away with having an empty delimiter.
103             # The second for is there to not error on empty lines: https://stackoverflow.com/a/31316333
104 0           return <
105             SET PATH=$path
106             doskey rakubrew="$brew_exec" internal_hooked Cmd \$* && FOR /f "delims=" \%i in ('"$brew_exec" internal_shell_hook Cmd post_call_eval \$*') do \@\%i
107             EOT
108             }
109              
110             sub post_call_eval {
111 0     0 0   my $self = shift;
112 0           $self->print_shellmod_code(@_);
113             }
114              
115             sub get_path_setter_code {
116 0     0 0   my $self = shift;
117 0           my $path = shift;
118 0           return "SET PATH=$path";
119             }
120              
121             sub get_shell_setter_code {
122 0     0 0   my $self = shift;
123 0           my $version = shift;
124 0           return "SET $env_var=$version"
125             }
126              
127             sub get_shell_unsetter_code {
128 0     0 0   my $self = shift;
129 0           return "UNSET $env_var";
130             }
131              
132             1;