-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
49 lines (44 loc) · 1.02 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
using CliWrap;
using CliWrap.Buffered;
using CliWrap.Exceptions;
if (args.Length == 0)
{
// Nothing to do
Console.WriteLine("kns: Nothing to do!");
return;
}
var path = args[0].Split(':');
var context = path.Length > 1 ? path[0] : "";
var ns = path.Length > 1 ? path[1] : path[0];
if (!string.IsNullOrEmpty(context))
{
// Set context
try
{
var _ = await Cli.Wrap("kubectx")
.WithArguments(context)
.ExecuteBufferedAsync();
Console.WriteLine($"Switched to context \"{context}\"");
}
catch (CommandExecutionException e)
{
Console.WriteLine(e.Message);
return;
}
}
if (!string.IsNullOrEmpty(ns))
{
// Set namespace
try
{
var _ = await Cli.Wrap("kubens")
.WithArguments(ns)
.ExecuteBufferedAsync();
Console.WriteLine($"Active namespace is \"{ns}\"");
}
catch (CommandExecutionException e)
{
Console.WriteLine(e.Message);
return;
}
}