-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
111 lines (90 loc) · 3.2 KB
/
Program.cs
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
using JKToolKit.Spectre.AutoCompletion.Completion;
using JKToolKit.Spectre.AutoCompletion.Integrations.Powershell;
using Spectre.Console.Cli;
using System.Diagnostics;
namespace AutoCompletionExample;
// Adding autocomplete to powershell:
// - .\AutoCompletionExample.exe completion powershell
//
// Adding autocomplete to powershell (permanent):
// - .\AutoCompletionExample.exe completion powershell --install
//
// Test completing:
// - .\AutoCompletionExample.exe cli complete "myapp Li"
internal static class Program
{
private static void Main(string[] args)
{
// If we just want to test the completion with f5 in visual studio
if (Debugger.IsAttached)
{
// args = new[] { "completion", "complete", "\"myapp Li\"" };
// completion complete --position 16 my lion --teeth
args = new[] { "completion", "complete", "--position", "16", "my lion --teeth " };
}
LogToFile(args);
var app = new CommandApp();
app.Configure
(
config =>
{
config
.AddAutoCompletion(x => x.AddPowershell(opts => opts
.WithAlias("myls", ["ls"])
.WithAlias("my")
.WithAlias("mylion", ["lion"])
.WithAlias("clion", ["lion", "5"])
))
.AddCommand<LionCommand>("lion")
;
config.AddCommand<LsCommand>("ls")
.WithDescription("List files and directories in the current directory.");
config.PropagateExceptions();
}
);
try
{
app.Run(args);
}
catch (Exception ex)
{
if (Debugger.IsAttached)
{
throw;
}
File.AppendAllText("Error.txt", ex.ToString() +
"\n-------------------\n");
}
}
private static void LogToFile(string[] args)
{
if (Debugger.IsAttached)
{
return;
}
var myargs = args
.Select(x => x.Contains(" ") ? $"\"{x}\"" : x);
var log = string.Join(" ", myargs);
System.IO.File.AppendAllText("log.txt", log + "\n");
}
// log stdout to file
//private static void LogStdoutToFile()
//{
// var stdout = new System.IO.StreamWriter("stdout.txt");
// System.Console.SetOut(stdout);
//}
}
/*
export SAMPLE_DLL=/mnt/c/Users/W31rd0/source/repos/JKamsker/JKToolKit/src/Samples/AutoCompletionExample/bin/Release/net7.0/publish/AutoCompletionExample.dll
# using SAMPLE_DLL: dotnet $SAMPLE_DLL
# completion: dotnet $SAMPLE_DLL cli complete "myapp li"
# bash parameter completion for the dotnet CLI
function _dotnet_bash_complete()
{
local cur="${COMP_WORDS[COMP_CWORD]}" IFS=$'\n' # On Windows you may need to use use IFS=$'\r\n'
local candidates
read -d '' -ra candidates < <(dotnet $SAMPLE_DLL cli complete --position "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)
read -d '' -ra COMPREPLY < <(compgen -W "${candidates[*]:-}" -- "$cur")
}
complete -f -F _dotnet_bash_complete AutoCompletionExample
*/