Skip to content

Commit 1fea7d6

Browse files
Merge pull request #275 from bilal-fazlani/v4/master
V4/master
2 parents 56ab472 + 2cf2f6e commit 1fea7d6

File tree

297 files changed

+3556
-3139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

297 files changed

+3556
-3139
lines changed

.travis.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
language: csharp
22
mono: none
33

4+
addons:
5+
apt:
6+
packages: dotnet-sdk-3.1
7+
homebrew:
8+
packages: dotnet
9+
410
notifications:
511
webhooks:
612
urls:
@@ -23,23 +29,39 @@ jobs:
2329
- stage: test
2430
name: test on osx
2531
os: osx
26-
script: dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
27-
dotnet: 2.1.300
32+
# https://travis-ci.community/t/c-build-with-netcore3-1-failed-on-mac-os-and-succed-on-linux/7860
33+
dotnet: 3.1.200
34+
install:
35+
- dotnet restore
36+
script:
37+
- dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
2838
- name: test on linux
2939
os: linux
30-
script: dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
31-
dotnet: 2.1
40+
dotnet: 3.1
41+
install:
42+
- dotnet restore
43+
script:
44+
- dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
3245
- name: test on windows
3346
os: windows
34-
script: dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
47+
script:
48+
- choco install dotnetcore-sdk
49+
- dotnet --version
50+
- dotnet restore
51+
- dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
3552
#-----------------------------------
3653

3754
#--------- DEPLOYMENT JOB ----------
3855
- stage: deploy
3956
name: nuget & github release
40-
script: ./deploy.sh
4157
os: linux
42-
dotnet: 2.1
58+
dotnet: 3.1
59+
install:
60+
- dotnet restore
61+
script:
62+
- dotnet test CommandDotNet.Tests/CommandDotNet.Tests.csproj
63+
script:
64+
- ./deploy.sh
4365
env:
4466
- secure: rzK8y4HE7yCVPStFdVttd1ApJ15xGhiGObJsHifi5ulaR/4POUU5o+6Bf/kLxCbhPeK0VBT5Zlt2WUNYq19IF8PbwZqADMQwc8NJVYX78UEbtbq5NaI2xFTbLC5Ng8GWcl5cEhl68pTMHIbqkAmUW7H3ESQVqz7DBG2oehCWXlEggI6hiXgS/QWE/W6YdLMoitPZTATeM1FXs3ZT1IMRGCpcl4mVkK8bEr8fFemujWOD7ymZYZUAr97B9u6oPz/mgW0BsWKNQfHkS6t92N/1WZyX8voJ4hszKvJedYaw3u8FVJvG4KNhMtT24GQl2b8MCkqVo6U41kRHSfkg5uNIigSy/mYKyT8WQWf/bT/WrKyVSepKcHaT1rYdKac/hmOTa66804P44ZTa9l0J2r9fTEg7qPRmC83e81KprIg6WptE9UpN9bRjtzULa7gZyAtoO8TgUCEt1+siP/cGqUtU/gwG4Pv/Bgxy6CIda5NLzNDCTZqWdkJkdogKLFDzjawDn1LG8j8SlGo7h6wb92YcS+EQLww4fk6CSJU7IY35tfzxGG3onWvR9sUn4bjulROOIVAEmpwzLmuSsvQZ5Jv8dnp6m0KPJGHFJWzYPUsmVDFPRZul6y1MROIax36AtQnUCu3LMQu5dAwizOvmmE6DPopfJjn1gHiFHU/nSL7Qcgg=
4567
#-----------------------------------

CommandDotNet.Example/CommandDotNet.Example.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
<PackageReference Include="FluentValidation.ValidatorAttribute" Version="8.0.0" />
1616
<PackageReference Include="Humanizer.Core" Version="2.7.9" />
1717
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
18+
<PackageReference Include="Nullable" Version="1.2.1">
19+
<PrivateAssets>all</PrivateAssets>
20+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
21+
</PackageReference>
1822
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
1923
</ItemGroup>
2024
</Project>

CommandDotNet.Example/Commands/Git.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace CommandDotNet.Example.Commands
66
public class Git
77
{
88
[SubCommand]
9-
public Submodule SubmoduleProperty { get; set; }
9+
public Submodule? SubmoduleProperty { get; set; }
1010

1111
[SubCommand]
1212
public class Remote
@@ -30,19 +30,19 @@ public class Stash
3030
[DefaultMethod]
3131
public void DoStash()
3232
{
33-
Console.WriteLine($"changes stashed");
33+
Console.WriteLine("changes stashed");
3434
}
3535

3636
[Command(Name = "pop", Description = "Applies last stashed changes")]
3737
public void Pop()
3838
{
39-
Console.WriteLine($"stash popped");
39+
Console.WriteLine("stash popped");
4040
}
4141

4242
[Command(Name = "list", Description = "Lists all saved stashed changes")]
4343
public void List()
4444
{
45-
Console.WriteLine($"here's the list of stash");
45+
Console.WriteLine("here's the list of stash");
4646
}
4747
}
4848

CommandDotNet.Example/Commands/Models.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ public class VerbosityArgs : IArgumentModel
6868
[Validator(typeof(NotificationValidator))]
6969
public class Notification : IArgumentModel
7070
{
71-
public string Email { get; set; }
71+
[Operand]
72+
public string? Email { get; set; }
7273

73-
public List<string> Messages { get; set; }
74+
[Operand]
75+
public List<string>? Messages { get; set; }
7476

75-
public NotificationOptions NotificationOptions { get; set; }
77+
[Operand]
78+
public NotificationOptions? NotificationOptions { get; set; }
7679
}
7780

7881
public class NotificationOptions : IArgumentModel

CommandDotNet.Example/Commands/Prompts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Task<int> Intercept(InterceptorExecutionDelegate next,
3737
return ExitCodes.Error;
3838
}
3939

40-
console.Out.WriteLine($"authenticated as user:{username} with password:{password} (actual password:{password.GetPassword()})");
40+
console.Out.WriteLine($"authenticated as user:{username} with password:{password} (actual password:{pwd})");
4141

4242
return next();
4343
}

CommandDotNet.Example/DocExamples/Git.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ public class Stash
1818
[DefaultMethod]
1919
public void StashDefaultCommand()
2020
{
21-
Console.WriteLine($"changes stashed");
21+
Console.WriteLine("changes stashed");
2222
}
2323

2424
[Command(Description = "Applies last stashed changes")]
2525
public void Pop()
2626
{
27-
Console.WriteLine($"stash popped");
27+
Console.WriteLine("stash popped");
2828
}
2929

3030
[Command(Description = "Lists all stashed changes")]
3131
public void List()
3232
{
33-
Console.WriteLine($"here's the list of stash");
33+
Console.WriteLine("here's the list of stash");
3434
}
3535
}
3636
}

CommandDotNet.Example/DocExamples/RocketLauncher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using CommandDotNet.Extensions;
43

54
namespace CommandDotNet.Example.DocExamples
65
{

CommandDotNet.Example/Examples.cs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,43 @@ namespace CommandDotNet.Example
1414
"Example: %UsageAppName% [debug] [parse] [log:info] cancel-me")]
1515
internal class Examples
1616
{
17+
private static bool _inSession;
18+
19+
[DefaultMethod]
20+
public void StartSession(
21+
CommandContext context,
22+
InteractiveSession interactiveSession,
23+
[Option(ShortName = "i")] bool interactive)
24+
{
25+
if (interactive && !_inSession)
26+
{
27+
context.Console.WriteLine("start session");
28+
_inSession = true;
29+
interactiveSession.Start();
30+
}
31+
else
32+
{
33+
context.Console.WriteLine($"no session {interactive} {_inSession}");
34+
context.ShowHelpOnExit = true;
35+
}
36+
}
37+
1738
[SubCommand]
18-
public Git Git { get; set; }
39+
public Git Git { get; set; } = null!;
1940

2041
[SubCommand]
21-
public Math Math { get; set; }
42+
public Math Math { get; set; } = null!;
2243

2344
[SubCommand]
24-
public Models Models { get; set; }
45+
public Models Models { get; set; } = null!;
2546

2647
[SubCommand]
27-
public Pipes Pipes { get; set; }
48+
public Pipes Pipes { get; set; } = null!;
2849

2950
[SubCommand]
30-
public CancelMe CancelMe { get; set; }
51+
public CancelMe CancelMe { get; set; } = null!;
3152

3253
[SubCommand]
33-
public Commands.Prompts Prompts { get; set; }
54+
public Commands.Prompts Prompts { get; set; } = null!;
3455
}
3556
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace CommandDotNet.Example
2+
{
3+
public static class InteractiveMiddleware
4+
{
5+
public static AppRunner UseInteractiveMode(this AppRunner appRunner, string appName)
6+
{
7+
return appRunner.Configure(c =>
8+
{
9+
// use the existing appRunner to reuse the configuration.
10+
c.UseParameterResolver(ctx => new InteractiveSession(appRunner, appName, ctx));
11+
});
12+
}
13+
}
14+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Linq;
3+
using CommandDotNet.Builders;
4+
using CommandDotNet.Tokens;
5+
6+
namespace CommandDotNet.Example
7+
{
8+
public class InteractiveSession
9+
{
10+
private readonly AppRunner _appRunner;
11+
private readonly string _appName;
12+
private readonly CommandContext _context;
13+
14+
public InteractiveSession(AppRunner appRunner, string appName, CommandContext context)
15+
{
16+
_appRunner = appRunner;
17+
_appName = appName;
18+
_context = context;
19+
}
20+
21+
public void Start()
22+
{
23+
var console = _context.Console;
24+
var cancellationToken = _context.CancellationToken;
25+
26+
bool pressedCtrlC = false;
27+
Console.CancelKeyPress += (sender, args) =>
28+
{
29+
pressedCtrlC = true;
30+
};
31+
32+
PrintSessionInit();
33+
34+
bool pendingNewLine = false;
35+
void Write(string? value = null)
36+
{
37+
console!.Write(value);
38+
pendingNewLine = true;
39+
}
40+
41+
void WriteLine(string? value = null)
42+
{
43+
console!.WriteLine(value);
44+
pendingNewLine = false;
45+
}
46+
47+
void EnsureNewLine()
48+
{
49+
if (pendingNewLine)
50+
{
51+
WriteLine();
52+
}
53+
}
54+
55+
while (!cancellationToken.IsCancellationRequested)
56+
{
57+
EnsureNewLine();
58+
Write(">>>");
59+
var input = console.In.ReadLine();
60+
if (input is null || pressedCtrlC)
61+
{
62+
pressedCtrlC = false;
63+
WriteLine();
64+
return;
65+
}
66+
67+
var args = new CommandLineStringSplitter().Split(input).ToArray();
68+
if (args.Length == 0)
69+
{
70+
WriteLine();
71+
continue;
72+
}
73+
if (args.Length == 1)
74+
{
75+
var singleArg = args[0];
76+
switch (singleArg)
77+
{
78+
case "exit":
79+
case "quit":
80+
return;
81+
case "help":
82+
PrintSessionHelp();
83+
continue;
84+
}
85+
if (singleArg == Environment.NewLine)
86+
{
87+
WriteLine();
88+
continue;
89+
}
90+
}
91+
EnsureNewLine();
92+
_appRunner.Run(args);
93+
}
94+
EnsureNewLine();
95+
}
96+
97+
private void PrintSessionInit()
98+
{
99+
var appInfo = AppInfo.GetAppInfo(_context);
100+
var console = _context.Console;
101+
console.WriteLine($"{_appName} {appInfo.Version}");
102+
console.WriteLine("Type 'help' to see interactive options");
103+
console.WriteLine("Type '-h' or '--help' to options for commands");
104+
console.WriteLine("Type 'exit', 'quit' or 'Ctrl+C' to exit.");
105+
}
106+
107+
private void PrintSessionHelp()
108+
{
109+
var console = _context.Console;
110+
console.WriteLine("Type '-h' or '--help' to options for commands");
111+
console.WriteLine("Type 'exit', 'quit' or 'Ctrl+C' to exit.");
112+
}
113+
}
114+
}

0 commit comments

Comments
 (0)