Skip to content

Commit da44bd6

Browse files
authored
Adds Documentation (#10)
* Add nuget package instead of project reference * Update readme with some configuration documentation. * Add warnings * Add documentation to public API * Update nuspec to v1.0.2 * Update spec
1 parent 33bf208 commit da44bd6

29 files changed

Lines changed: 530 additions & 44 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using MatthiWare.CommandLine;
6+
using Xunit;
7+
8+
namespace MatthiWare.CommandLineParser.Tests.Command
9+
{
10+
public class CommandTests
11+
{
12+
13+
[Fact]
14+
public void ConfiguringCommandsIncreasesTotalCommandInParser()
15+
{
16+
var parser = new CommandLineParser<object>();
17+
18+
parser.AddCommand<object>().Name("x");
19+
parser.AddCommand<object>().Name("y");
20+
21+
Assert.Equal(2, parser.Commands.Count);
22+
23+
Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("x")));
24+
Assert.NotNull(parser.Commands.First(cmd => cmd.ShortName.Equals("y")));
25+
}
26+
27+
}
28+
}

CommandLineParser.Tests/CommandLineArgumentOptionTest.cs

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

CommandLineParser.Tests/CommandLineParser.Tests.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,4 @@
2222
<ProjectReference Include="..\CommandLineParser\CommandLineParser.csproj" />
2323
</ItemGroup>
2424

25-
<ItemGroup>
26-
<Folder Include="Command\" />
27-
</ItemGroup>
28-
2925
</Project>

CommandLineParser/Abstractions/Command/ICommandBuilder'.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,53 @@
33

44
namespace MatthiWare.CommandLine.Abstractions.Command
55
{
6+
/// <summary>
7+
/// Configures commands using a fluent interface
8+
/// </summary>
9+
/// <typeparam name="Tsource">Command options class</typeparam>
610
public interface ICommandBuilder<Tsource> where Tsource : class, new()
711
{
12+
/// <summary>
13+
/// Configures if the command is required
14+
/// </summary>
15+
/// <param name="required">True or false</param>
16+
/// <returns><see cref="ICommandBuilder{Tsource}"/></returns>
817
ICommandBuilder<Tsource> Required(bool required = true);
918

19+
/// <summary>
20+
/// Configures the help text for the command
21+
/// </summary>
22+
/// <param name="required">True or false</param>
23+
/// <returns><see cref="ICommandBuilder{Tsource}"/></returns>
1024
ICommandBuilder<Tsource> HelpText(string help);
1125

26+
/// <summary>
27+
/// Configures the command name
28+
/// </summary>
29+
/// <param name="shortName">Short name</param>
30+
/// <returns><see cref="ICommandBuilder{Tsource}"/></returns>
1231
ICommandBuilder<Tsource> Name(string shortName);
1332

33+
/// <summary>
34+
/// Configures the command name
35+
/// </summary>
36+
/// <param name="shortName">Short name</param>
37+
/// <param name="longName">Long name</param>
38+
/// <returns><see cref="ICommandBuilder{Tsource}"/></returns>
1439
ICommandBuilder<Tsource> Name(string shortName, string longName);
1540

41+
/// <summary>
42+
/// Configures the execution of the command
43+
/// </summary>
44+
/// <param name="required">True or false</param>
45+
/// <returns><see cref="ICommandBuilder{Tsource}"/></returns>
1646
ICommandBuilder<Tsource> OnExecuting(Action<Tsource> action);
1747

48+
/// <summary>
49+
/// Configures if the command options
50+
/// </summary>
51+
/// <param name="selector">Property to configure</param>
52+
/// <returns><see cref="IOptionBuilder"/></returns>
1853
IOptionBuilder Configure<TProperty>(Expression<Func<Tsource, TProperty>> selector);
1954
}
2055
}

CommandLineParser/Abstractions/Command/ICommandLineCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace MatthiWare.CommandLine.Abstractions.Command
22
{
3+
/// <summary>
4+
/// Command configuration options
5+
/// </summary>
36
public interface ICommandLineCommand
47
{
58
string ShortName { get; }

CommandLineParser/Abstractions/Command/ICommandLineCommandParser.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@
44

55
namespace MatthiWare.CommandLine.Abstractions.Command
66
{
7+
/// <summary>
8+
/// Parser for a command line command
9+
/// </summary>
710
public interface ICommandLineCommandParser
811
{
12+
/// <summary>
13+
/// Read-only collection of the options for the command
14+
/// </summary>
915
IReadOnlyList<ICommandLineOption> Options { get; }
16+
17+
/// <summary>
18+
/// Parses the arguments
19+
/// </summary>
20+
/// <param name="argumentManager">Arguments to parse</param>
21+
/// <returns><see cref="ICommandParserResult"/></returns>
1022
ICommandParserResult Parse(IArgumentManager argumentManager);
1123
}
1224
}

CommandLineParser/Abstractions/ICommandLineOption.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
namespace MatthiWare.CommandLine.Abstractions
44
{
5+
/// <summary>
6+
/// Option configuration options
7+
/// </summary>
58
public interface ICommandLineOption : ICommandLineCommand
69
{
7-
10+
811
}
912
}

CommandLineParser/Abstractions/ICommandLineParser'.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,52 @@ public interface ICommandLineParser<TSource>
1010
{
1111
#region Properties
1212

13+
/// <summary>
14+
/// Read-only list of available sub-commands
15+
/// <see cref="ICommandLineParser{TSource}.AddCommand{TCommandOption}"/> to configure or add an command
16+
/// </summary>
1317
IReadOnlyList<ICommandLineCommand> Commands { get; }
18+
19+
/// <summary>
20+
/// Read-only list of available options for this command
21+
/// <see cref="ICommandLineParser{TSource}.Configure{TProperty}(Expression{Func{TSource, TProperty}})"/> to configure or add an option
22+
/// </summary>
1423
IReadOnlyList<ICommandLineOption> Options { get; }
24+
25+
/// <summary>
26+
/// Factory to resolve the argument type
27+
/// <see cref="ICommandLineArgumentResolver"/> for more info.
28+
/// </summary>
1529
IResolverFactory ResolverFactory { get; }
1630

1731
#endregion
1832

1933
#region Parsing
2034

35+
/// <summary>
36+
/// Parses the current command and returns the result
37+
/// </summary>
38+
/// <param name="args">command arguments</param>
39+
/// <returns>The <see cref="IParserResult{TResult}"/> result</returns>
2140
IParserResult<TSource> Parse(string[] args);
2241

2342
#endregion
2443

2544
#region Configuration
2645

46+
/// <summary>
47+
/// Configures a new or existing option
48+
/// </summary>
49+
/// <typeparam name="TProperty">The property type</typeparam>
50+
/// <param name="selector">Property selector</param>
51+
/// <returns><see cref="IOptionBuilder"/></returns>
2752
IOptionBuilder Configure<TProperty>(Expression<Func<TSource, TProperty>> selector);
2853

54+
/// <summary>
55+
/// Adds a new command and allowes to configure it.
56+
/// </summary>
57+
/// <typeparam name="TCommandOption">Command options model</typeparam>
58+
/// <returns>A command builder, see <see cref="ICommandBuilder{Tsource}"/> for more info.</returns>
2959
ICommandBuilder<TCommandOption> AddCommand<TCommandOption>() where TCommandOption : class, new();
3060

3161
#endregion
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,44 @@
11
namespace MatthiWare.CommandLine.Abstractions
22
{
3+
/// <summary>
4+
/// API for configuring options
5+
/// </summary>
36
public interface IOptionBuilder
47
{
8+
/// <summary>
9+
/// Sets if the option is required
10+
/// </summary>
11+
/// <param name="required">Required or not</param>
12+
/// <returns><see cref="IOptionBuilder"/></returns>
513
IOptionBuilder Required(bool required = true);
614

15+
/// <summary>
16+
/// Help text to be displayed for this option
17+
/// </summary>
18+
/// <param name="help"></param>
19+
/// <returns></returns>
720
IOptionBuilder HelpText(string help);
821

22+
/// <summary>
23+
/// Specify the default value for this option
24+
/// </summary>
25+
/// <param name="defaultValue"></param>
26+
/// <returns></returns>
927
IOptionBuilder Default(object defaultValue);
1028

29+
/// <summary>
30+
/// Configures the name for the option
31+
/// </summary>
32+
/// <param name="shortName">short name</param>
33+
/// <returns></returns>
1134
IOptionBuilder Name(string shortName);
1235

36+
/// <summary>
37+
/// Configures the name for the option
38+
/// </summary>
39+
/// <param name="shortName">Short name</param>
40+
/// <param name="longName">Long name</param>
41+
/// <returns></returns>
1342
IOptionBuilder Name(string shortName, string longName);
1443
}
1544
}
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
namespace MatthiWare.CommandLine.Abstractions.Models
22
{
3+
/// <summary>
4+
/// Model for command line arguments
5+
/// </summary>
36
public struct ArgumentModel
47
{
8+
/// <summary>
9+
/// Argument identifier
10+
/// </summary>
511
public string Key { get; set; }
612

13+
/// <summary>
14+
/// Value of the argument
15+
/// Can be null
16+
/// </summary>
717
public string Value { get; set; }
818

19+
/// <summary>
20+
/// Checks if an value has been provided in the model
21+
/// </summary>
922
public bool HasValue => Value != null;
1023

24+
/// <summary>
25+
/// Creates a new instance of the argument model
26+
/// </summary>
27+
/// <param name="key">model identifier</param>
28+
/// <param name="value">model value</param>
1129
public ArgumentModel(string key, string value)
1230
{
1331
this.Key = key;
1432
this.Value = value;
1533
}
16-
17-
public ArgumentModel(string key)
18-
{
19-
this.Key = key;
20-
this.Value = null;
21-
}
2234
}
2335
}

0 commit comments

Comments
 (0)