MCPcopy Create free account
hub / github.com/PerroEngine/Perro / install_command

Function install_command

perro_source/devtools/perro_cli/src/install.rs:9–60  ·  view source on GitHub ↗
(args: &[String])

Source from the content-addressed store, hash-verified

7const PROFILE_SNIPPET_END: &str = "# <<< perro_cli source-mode <<<";
8
9pub(crate) fn install_command(args: &[String]) -> Result<(), String> {
10 let explicit_profile = parse_flag_value(args, "--profile").map(PathBuf::from);
11
12 if cfg!(target_os = "windows") {
13 let profile_paths = if let Some(path) = explicit_profile {
14 vec![path]
15 } else {
16 default_powershell_profile_paths()
17 };
18 let workspace_manifest =
19 normalize_powershell_path(&workspace_root().join("Cargo.toml")).replace('\\', "\\\\");
20 let snippet = format!(
21 "{PROFILE_SNIPPET_BEGIN}\n\
22function perro {{\n\
23 param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Args)\n\
24 $manifest = \"{workspace_manifest}\"\n\
25 cargo build --manifest-path $manifest -p perro_cli\n\
26 if ($LASTEXITCODE -ne 0) {{ return }}\n\
27 $root = Split-Path -Parent $manifest\n\
28 $targetDir = if ($env:CARGO_TARGET_DIR) {{ $env:CARGO_TARGET_DIR }} else {{ Join-Path $root \"target\" }}\n\
29 $cliExe = Join-Path $targetDir \"debug\\perro_cli.exe\"\n\
30 $runRoot = Join-Path ([System.IO.Path]::GetTempPath()) \"perro_cli_runs\"\n\
31 New-Item -ItemType Directory -Force -Path $runRoot | Out-Null\n\
32 Get-ChildItem -Path $runRoot -Directory -ErrorAction SilentlyContinue | Where-Object {{ $_.LastWriteTimeUtc -lt (Get-Date).ToUniversalTime().AddDays(-7) }} | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue\n\
33 $stamp = Get-Item -LiteralPath $cliExe\n\
34 $runDir = Join-Path $runRoot (\"build-\" + $stamp.Length + \"-\" + $stamp.LastWriteTimeUtc.Ticks)\n\
35 $runExe = Join-Path $runDir \"perro_cli.exe\"\n\
36 if (-not (Test-Path -LiteralPath $runExe)) {{\n\
37 New-Item -ItemType Directory -Force -Path $runDir | Out-Null\n\
38 Copy-Item -LiteralPath $cliExe -Destination $runExe -Force\n\
39 }}\n\
40 & $runExe @Args\n\
41}}\n\
42{PROFILE_SNIPPET_END}\n"
43 );
44 install_snippet_into_profiles(&profile_paths, &snippet)?;
45 if let Some(primary) = profile_paths.first() {
46 println!("restart PowerShell or run: . \"{}\"", primary.display());
47 }
48 return Ok(());
49 }
50
51 if cfg!(target_os = "linux") {
52 let profile_paths = if let Some(path) = explicit_profile {
53 vec![path]
54 } else {
55 default_posix_profile_paths()
56 };
57 let workspace_manifest = shell_single_quote_path(&workspace_root().join("Cargo.toml"));
58 let snippet = format!(
59 "{PROFILE_SNIPPET_BEGIN}\n\
60perro() {{\n\
61 manifest={workspace_manifest}\n\
62 cargo build --manifest-path \"$manifest\" -p perro_cli || return\n\
63 root=$(dirname \"$manifest\")\n\

Callers 1

mainFunction · 0.85

Calls 8

shell_single_quote_pathFunction · 0.85
joinMethod · 0.80
parse_flag_valueFunction · 0.70
workspace_rootFunction · 0.70

Tested by

no test coverage detected