Skip to content

Commit e0e398d

Browse files
committed
# Release v4.9.4.0
--- ## Changes ### CLI - #406: Custom DLL (CommandGathering.dll) Fails Compile-Time Namespace Resolution with //css_ref - Improved `css -cmd` UX when generating custom commands descriptions. - Updated custom commands `-pkill` to allow killing the process by PID. - Added custom commands: - `-runas` - `-which` - `-who`
1 parent 4a5e2d6 commit e0e398d

File tree

23 files changed

+203
-81
lines changed

23 files changed

+203
-81
lines changed

src/CSScriptLib/src/CSScriptLib/CSScriptLib.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232

3333
- #406: Custom DLL (CommandGathering.dll) Fails Compile-Time Namespace Resolution with //css_ref
3434
- Improved `css -cmd` UX when generating custom commands descriptions.
35+
- Updated custom commands `-pkill` to allow killing the process by PID.
36+
- Added custom commands:
37+
- `-runas`
38+
- `-which`
39+
- `-who`
3540

3641
### CSScriptLib
3742

src/Tests.cscs/Utils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FactWinOnlyAttribute : Attribute
1111

1212
static class Extensions
1313
{
14-
public static string Run(this string exe, string args = null, string dir = null)
14+
public static (string output, int exitCode) Run(this string exe, string args = null, string dir = null)
1515
{
1616
var process = new Process();
1717

@@ -29,6 +29,6 @@ public static string Run(this string exe, string args = null, string dir = null)
2929
output += process.StandardError.ReadToEnd();
3030
process.WaitForExit();
3131

32-
return output;
32+
return (output, process.ExitCode);
3333
}
3434
}

src/Tests.cscs/cli.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
using System.IO;
55
using System.Linq;
66
using System.Reflection;
7+
using System.Runtime.CompilerServices;
8+
using System.Runtime.InteropServices;
9+
using System.Threading;
10+
using System.Threading.Tasks;
711
using csscript;
812
using CSScripting;
913
using CSScriptLib;
@@ -49,7 +53,7 @@ public cscs_cli(ITestOutputHelper output)
4953
var cmd_dir = cscs_exe.ChangeFileName("-self");
5054

5155
if (cmd_dir.DirExists())
52-
static_content = cmd_dir;
56+
static_content = cmd_dir.GetFileName();
5357
else
5458
static_content = $@"..\..\..\..\..\out\static_content".GetFullPath();
5559

@@ -61,14 +65,23 @@ public cscs_cli(ITestOutputHelper output)
6165
public string cscs_exe;
6266
public string static_content;
6367

64-
string cscs_run(string args, string dir = null) => "dotnet".Run($"\"{cscs_exe}\" {args}", dir).Trim();
68+
string cscs_run(string args, string dir = null)
69+
{
70+
var output = "dotnet".Run($"\"{cscs_exe}\" {args}", dir).output.Trim();
71+
if (args.TrimStart().StartsWith("-new"))
72+
Task.Delay(700).Wait(); // give it a chance to complete and get accessible (e.g. AV release the lock)
73+
return output;
74+
}
75+
76+
(string, int) cscs_runx(string args, string dir = null) => "dotnet".Run($"\"{cscs_exe}\" {args}", dir);
6577

6678
[Fact]
6779
public void create_and_execute_default_script()
6880
{
6981
var script_file = nameof(create_and_execute_default_script) + ".cs";
7082

7183
var output = cscs_run($"-new {script_file}");
84+
7285
Assert.True(File.Exists(script_file));
7386

7487
Assert.True(File.Exists(script_file));
@@ -103,6 +116,7 @@ public void switch_engine_from_code_with_full_directive()
103116
var script_file = nameof(switch_engine_from_code_with_full_directive) + ".cs";
104117

105118
var output = cscs_run($"-new {script_file}");
119+
106120
var script_code = File.ReadAllText(script_file);
107121

108122
// full directive //css_engine
@@ -245,6 +259,28 @@ public void syntax_version_10()
245259
Assert.Equal("Hello, World!", output);
246260
}
247261

262+
[Fact]
263+
public void distro_commands()
264+
{
265+
var is_win = (Environment.OSVersion.Platform == PlatformID.Win32NT);
266+
267+
var commands = Directory.GetFiles(static_content, "-run.cs", SearchOption.AllDirectories);
268+
foreach (var file in commands)
269+
{
270+
var cmd = file.GetDirName().GetFileName();
271+
272+
var probing_dir = $"-dir:{static_content}";
273+
var extra_arg = cmd.IsOneOf("-web", "-update") ? "-?" : "";
274+
275+
(var output, var exitCode) = cscs_runx($"{file} {extra_arg}");
276+
277+
var context = $"{file}\n{output.TakeMax(100)}";
278+
279+
Assert.True(0 == exitCode, $"Failed to build/execute: \n{context}");
280+
Assert.False(output.Contains("Index was"), $"Failed to start: \n{context}");
281+
}
282+
}
283+
248284
[Fact]
249285
public void complex_commands()
250286
{
@@ -399,13 +435,13 @@ static void Main()
399435
[Fact]
400436
public void compiler_output()
401437
{
402-
// Debugger.Break();
438+
// Debugger.Launch();
403439
var script_file = nameof(compiler_output);
404440
var output = cscs_run($"-new {script_file}");
405441

406-
output = cscs_run($"-check -ng:csc {script_file}");
407-
// throw new Exception($"{output}\n{script_file}\n{Environment.CurrentDirectory}");
408-
Assert.Equal("Compile: OK", output);
442+
var output1 = cscs_run($"-check -ng:csc {script_file}");
443+
444+
Assert.Equal("Compile: OK", output1);
409445
}
410446

411447
[Fact]
@@ -443,6 +479,7 @@ public void new_wpf_with_cscs()
443479
var script_file = nameof(new_wpf_with_cscs) + ".cs";
444480

445481
var output = cscs_run($"-new:wpf {script_file}");
482+
Task.Delay(500).Wait();
446483

447484
// --------------
448485

src/chocolatey/cs-script.nuspec

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232

3333
- #406: Custom DLL (CommandGathering.dll) Fails Compile-Time Namespace Resolution with //css_ref
3434
- Improved `css -cmd` UX when generating custom commands descriptions.
35+
- Updated custom commands `-pkill` to allow killing the process by PID.
36+
- Added custom commands:
37+
- `-runas`
38+
- `-which`
39+
- `-who`
3540

3641
### CSScriptLib
3742

src/cscs/HelpProvider.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,6 @@ public static string ShowHelp(string helpType, params object[] context)
13691369

13701370
var description = cachedDescription;
13711371

1372-
var delayedDescription = true;
1373-
13741372
if (!description.HasText() || version.IsMatch(description) || File.GetLastWriteTimeUtc(versionFile) != File.GetLastWriteTimeUtc(commandFile))
13751373
{
13761374
(var result, description) = GenerateCommadDescription(item.Key);

src/cscs/Utils/CLIExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public static IEnumerable<XElement> FindDescendants(this XElement element, strin
6969
public static bool StartsWith(this string text, string pattern, bool ignoreCase) =>
7070
text.StartsWith(pattern, ignoreCase ? StringComparison.OrdinalIgnoreCase : default(StringComparison));
7171

72+
public static string TakeMax(this string text, int maxCharacters) =>
73+
text.Substring(0, Math.Min(100, text.Length));
74+
7275
public static string GetTargetPlatform(this CompilerParameters compilerParams)
7376
{
7477
var platform = compilerParams.CompilerOptions?

src/cscs/cscs.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
- #406: Custom DLL (CommandGathering.dll) Fails Compile-Time Namespace Resolution with //css_ref
2828
- Improved `css -cmd` UX when generating custom commands descriptions.
29+
- Updated custom commands `-pkill` to allow killing the process by PID.
30+
- Added custom commands:
31+
- `-runas`
32+
- `-which`
33+
- `-who`
2934

3035
### CSScriptLib
3136

@@ -130,6 +135,10 @@
130135
<Content Include="..\out\static_content\$-wdbg\**\*" Link="ToolPackage/-wdbg" Pack="true" PackagePath="tools/net9.0/any/-wdbg" />
131136
<Content Include="..\out\static_content\$-web\**\*" Link="ToolPackage/-web" Pack="true" PackagePath="tools/net9.0/any/-web" />
132137
<Content Include="..\out\static_content\$-web\**\*" Link="ToolPackage/-web" Pack="true" PackagePath="tools/net8.0/any/-web" />
138+
<Content Include="..\out\static_content\$-which\**\*" Link="ToolPackage/-which" Pack="true" PackagePath="tools/net9.0/any/-which" />
139+
<Content Include="..\out\static_content\$-which\**\*" Link="ToolPackage/-which" Pack="true" PackagePath="tools/net8.0/any/-which" />
140+
<Content Include="..\out\static_content\$-who\**\*" Link="ToolPackage/-who" Pack="true" PackagePath="tools/net9.0/any/-who" />
141+
<Content Include="..\out\static_content\$-who\**\*" Link="ToolPackage/-who" Pack="true" PackagePath="tools/net8.0/any/-who" />
133142
<!-- end: nuget tool package custom commands (keep this line here, it is a marker for automation) -->
134143
<Content Include="..\css\bin\net9.0-windows\csws.runtimeconfig.json" Link="ToolPackage/net.9" Pack="true" PackagePath="tools/net9.0/any/csws.runtimeconfig.json" />
135144
<Content Include="..\css\bin\net9.0-windows\csws.dll" Link="ToolPackage/net.9" Pack="true" PackagePath="tools/net9.0/any/csws.dll" />

src/csws/csws.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
- #406: Custom DLL (CommandGathering.dll) Fails Compile-Time Namespace Resolution with //css_ref
3131
- Improved `css -cmd` UX when generating custom commands descriptions.
32+
- Updated custom commands `-pkill` to allow killing the process by PID.
33+
- Added custom commands:
34+
- `-runas`
35+
- `-which`
36+
- `-who`
3237

3338
### CSScriptLib
3439

src/distro/which.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/out/Windows/-unlock/-run.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
1515
css -unlock <path>";
1616

17-
if (args.ContainsAny("-?", "?", "-help", "--help"))
17+
if (!args.Any() || args.ContainsAny("-?", "?", "-help", "--help"))
1818
{
1919
print(help);
2020
return;
2121
}
2222

23-
string path = args.FirstOrDefault() ?? CurrentDirectory;
23+
string path = args.FirstOrDefault().Locate();
2424

2525
if (Directory.Exists(path))
2626
{
@@ -77,4 +77,20 @@
7777
static class Extensions
7878
{
7979
public static bool ContainsAny(this string[] items1, params string[] items2) => items1.Intersect(items2).Any();
80+
81+
public static string Locate(this string path)
82+
{
83+
string fullPath;
84+
var dirs = Environment.GetEnvironmentVariable("Path").Split(';').ToList();
85+
dirs.Insert(0, Environment.CurrentDirectory);
86+
87+
foreach (string dir in dirs)
88+
{
89+
if (File.Exists(fullPath = Path.Combine(dir, path)))
90+
return fullPath;
91+
if (Directory.Exists(fullPath = Path.Combine(dir, path)))
92+
return fullPath;
93+
}
94+
return null;
95+
}
8096
}

0 commit comments

Comments
 (0)