-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfoSystem.ps1
More file actions
149 lines (124 loc) · 4.69 KB
/
Copy pathinfoSystem.ps1
File metadata and controls
149 lines (124 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
.SYNOPSIS
strideCore - Retrieve version, license, help, or library documentation.
.DESCRIPTION
This script accepts a command and an optional path.
--version : Display the script version.
--license : Display the content of the license file.
--help : Display general usage help.
--help <path> : Display documentation for a specific library.
.PARAMETER Command
The command: --version, --license, or --help
.PARAMETER Path
Optional library path for --help command
.EXAMPLE
.\stride.ps1 --version
.\stride.ps1 --license
.\stride.ps1 --help
.\stride.ps1 --help cgen\micros.h
.\stride.ps1 --help cgen/UnitTest.h
#>
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('--version', '--license', '--brief', '--help')]
[string]$Command,
[Parameter(Position = 1)]
[string]$Path = $null
)
# ===================== Global Settings =====================
$script:Version = "beta 0.0.3"
$script:LicenseFile = Join-Path -Path $PSScriptRoot -ChildPath "Documentation/lic.txt"
$script:DocRoot = "Documentation/text"
$script:briefFile = "Documentation/brief.txt"
# ===================== Helper Functions =====================
function Show-Version {
Write-Host "strideKit version $script:Version" -ForegroundColor Green
}
function Show-License {
if (Test-Path $script:LicenseFile) {
Write-Host "`n=== LICENSE ===`n" -ForegroundColor Yellow
Get-Content $script:LicenseFile | ForEach-Object { Write-Host $_ }
}
else {
Write-Error "License file not found: $script:LicenseFile"
Write-Host "Please create a lic.txt file in the 'Documentation' folder." -ForegroundColor Red
}
}
function Show-Brief {
if (Test-Path $script:briefFile) {
Write-Host "`n=============== BRIEF ===============`n" -ForegroundColor Yellow
Get-Content $script:briefFile | ForEach-Object { Write-Host $_ }
}
else {
Write-Error "Brief file not found: $script:briefFile"
Write-Host "Please create a brief.txt file in the 'Documentation' folder." -ForegroundColor Red
}
}
function Show-Help {
$helpText = @"
===========================================
strideCore - Information System
===========================================
Usage:
.\stride.ps1 --version
.\stride.ps1 --license
.\stride.ps1 --help
.\stride.ps1 --help <path>
Options:
--version : Show script version.
--license : Show license content (from Documentation/lic.txt).
--help : Show this help message.
--help <path> : Show documentation for a specific library.
<path> is the library file path (e.g., lite/micros.h).
The script looks for documentation at:
Documentation/text/<path_without_extension>.txt
Examples:
.\stride.ps1 --help strideKit/count.psm1
.\stride.ps1 --help staticCheck.bash
Note:
- The documentation root folder is 'Documentation/text' relative to the script location.
- Path separators can be '/' or '\' and are handled correctly.
- Any file extension is removed and replaced with .txt.
"@
Write-Host $helpText -ForegroundColor White
}
function Show-Documentation {
param([string]$LibraryPath)
# Normalize path separators to Windows backslash
$normalizedPath = $LibraryPath -replace '/', '\'
# Remove extension (everything after the last dot)
$withoutExt = $normalizedPath -replace '\.[^.]*$', ''
# Build the documentation file path inside Documentation/text
$docFileRelative = Join-Path -Path $script:DocRoot -ChildPath "$withoutExt.txt"
# Get absolute path (based on script location)
$docFullPath = Join-Path -Path $PSScriptRoot -ChildPath $docFileRelative
Write-Host "Looking for documentation of: $LibraryPath" -ForegroundColor Cyan
Write-Host "Expected documentation file: $docFileRelative" -ForegroundColor DarkGray
if (Test-Path $docFullPath) {
Write-Host "`n=== Documentation for: $LibraryPath ===`n" -ForegroundColor Yellow
Get-Content $docFullPath | ForEach-Object { Write-Host $_ }
}
else {
Write-Error "Documentation file not found: $docFileRelative"
Write-Host "Please ensure the file exists at: $docFullPath" -ForegroundColor Red
exit 1
}
}
# ===================== Main Logic =====================
if ($Command -eq "--version") {
Show-Version
}
elseif ($Command -eq "--license") {
Show-License
}
elseif ($Command -eq "--brief") {
Show-Brief
}
elseif ($Command -eq "--help") {
if ($Path) {
Show-Documentation -LibraryPath $Path
}
else {
Show-Help
}
}