Skip to content

Commit db98344

Browse files
committed
refactoring
1 parent 8befa33 commit db98344

File tree

16 files changed

+51
-51
lines changed

16 files changed

+51
-51
lines changed

Docs/Design_command.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Design your command
22

3-
Think of your command as an one line command with some parameters in a cmd prompt environment, it should do a small amount of isolated task in a specific context, for example lets say you want to convert yaml file to json or xml. A good name could be **ConvertCommand**, as parameters you have a path to the input file, and a flag for the format and a value to that flag. That is a pretty good design for one Command.
3+
Think of your command as an one line command with some parameters in a cmd prompt environment, it should do a small amount of isolated task in a specific context, for example lets say you want to convert yaml file to json or xml. A good name could be **ConvertCommand**, as parameters you have a path to the input file, and a O for the format and a value to that option. That is a pretty good design for one Command.
44

55
The usage of this command will look like this if I want to convert my yaml fil to json.
66

77
```convert "C:\temp\myYaml.yaml" --format json```
88

9-
If you want the input to be more self described, which the framework encourages you to do for clarity, you can choose to add a flag for the filepath like this:
9+
If you want the input to be more self described, which the framework encourages you to do for clarity, you can choose to add a option for the filepath like this:
1010

1111
```convert --file "C:\temp\myYaml.yaml" --format json```
1212

1313
There are other ways you can solve the design to, you can solve it with two Commands instead, one command named **XmlCommand** and another named **JsonCommand**, it is all up to you.
1414

1515
## Example code
1616
### Use case
17-
You want a simple Command that converts a yaml file to json or xml format. Your first architecture descision is, one command or two? Well, it is a matter of taste but for this example the choise is one single command that handles the conversion to both formats. We use two [Flags](Flags.md), one for the filename, named path and one for the format named format. I exclude the implementation code to keep the code example short. We pretend that we have a static class handling this format conversions.
17+
You want a simple Command that converts a yaml file to json or xml format. Your first architecture descision is, one command or two? Well, it is a matter of taste but for this example the choise is one single command that handles the conversion to both formats. We use two [Options](Options.md), one for the filename, named path and one for the format named format. I exclude the implementation code to keep the code example short. We pretend that we have a static class handling this format conversions.
1818

1919
```
2020
using PainKiller.PowerCommands.Core.Extensions;
@@ -23,23 +23,23 @@ using PainKiller.PowerCommands.MyExampleCommands.Configuration;
2323
namespace PainKiller.PowerCommands.MyExampleCommands.Commands;
2424
2525
[PowerCommandDesign( description: "Converting yaml format to json or xml format",
26-
flags: "path|format",
26+
options: "path|format",
2727
example: "//Convert to json format|convert --path \"c:\\temp\\test.yaml\" --format json|//Convert to xml format|convert --path \"c:\\temp\\test.yaml\" --format xml")]
2828
public class ConvertCommand : CommandBase<PowerCommandsConfiguration>
2929
{
3030
public ConvertCommand(string identifier, PowerCommandsConfiguration configuration) : base(identifier, configuration) { }
3131
3232
public override RunResult Run()
3333
{
34-
YamlFormatManger.Convert(Input.GetFlagValue("path"), Input.GetFlagValue("format"));
34+
YamlFormatManger.Convert(Input.GetOptionValue("path"), Input.GetOptionValue("format"));
3535
return Ok();
3636
}
3737
}
3838
```
39-
Notice that the documentation for how this command will be used is created with the [PowerCommandDesign](PowerCommandDesignAttribute.md) attribute. I realize that the path flag should be required, I can of course code this check in the Command but I do not need to do that, instead I declare that with the [PowerCommandDesign](PowerCommandDesignAttribute.md) attribute, I just add a **!** before the path flag, this will be validated before the execution of the run command. The new design look like this.
39+
Notice that the documentation for how this command will be used is created with the [PowerCommandDesign](PowerCommandDesignAttribute.md) attribute. I realize that the path option should be required, I can of course code this check in the Command but I do not need to do that, instead I declare that with the [PowerCommandDesign](PowerCommandDesignAttribute.md) attribute, I just add a **!** before the path option, this will be validated before the execution of the run command. The new design look like this.
4040
```
4141
[PowerCommandDesign( description: "Converting yaml format to json or xml format",
42-
flags: "!path|format",
42+
options: "!path|format",
4343
example: "//Convert to json format|convert --path \"c:\\temp\\test.yaml\" --format json|//Convert to xml format|convert --path \"c:\\temp\\test.yaml\" --format xml")]
4444
```
4545
If I run the command empty I trigger a validation error.
@@ -51,10 +51,10 @@ Lets have look of how the user input is designed.
5151

5252
![Alt text](images/Command_line_input_convert.png?raw=true "Describe convert command")
5353

54-
This input will first be handled by the Core Framework, using the Identifier an instanse of the ConvertCommand will be created and the framework will also add the [Input](Input.md) instance to the ConvertCommand instans wich give your convert command two flags named **path** and **format** to handle progamatically to create a file on the given path with the given format.
54+
This input will first be handled by the Core Framework, using the Identifier an instanse of the ConvertCommand will be created and the framework will also add the [Input](Input.md) instance to the ConvertCommand instans wich give your convert command two options named **path** and **format** to handle progamatically to create a file on the given path with the given format.
5555

5656
## Must I use the PowerCommandDesign attribute on every command I create?
57-
No that is not mandatory but it is recommended, note that when you declare the [Flags](Flags.md), they will be available for code completion, wich means that when the consumer types - and hit the tab button the user will can se what flags there are that could be used, with a simple ! character you tell that the argument, quote, flag or secret is required and then the Core runtime will validate that automatically for you. That is really nice, you could read more about design of good Command Line Inter fade design here:
57+
No that is not mandatory but it is recommended, note that when you declare the [Options](Options.md), they will be available for code completion, wich means that when the consumer types - and hit the tab button the user will can se what options there are that could be used, with a simple ! character you tell that the argument, quote, option or secret is required and then the Core runtime will validate that automatically for you. That is really nice, you could read more about design of good Command Line Inter fade design here:
5858

5959
Next step is to understand the [Power Commands Design attribute](PowerCommandDesignAttribute.md)
6060

@@ -65,6 +65,6 @@ Read more about:
6565

6666
[Input](Input.md)
6767

68-
[Flags](Flags.md)
68+
[Options](Options.md)
6969

7070
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)

Docs/Input.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface ICommandLineInput
1010
string Identifier { get; init; }
1111
string[] Quotes { get; init; }
1212
string[] Arguments { get; init; }
13-
string[] Flags { get; init; }
13+
string[] options { get; init; }
1414
string SingleArgument { get; }
1515
string SingleQuote { get; }
1616
string? Path { get; init; }
@@ -31,15 +31,15 @@ It could look something like this.
3131
```
3232
public override RunResult Run()
3333
{
34-
if(Input.HasFlag("hello")) WriteLine("Hello World!");
34+
if(Input.HasOption("hello")) WriteLine("Hello World!");
3535
return CreateRunResult();
3636
}
3737
```
3838

3939
## Properties and it´s usage
4040
For this example let´s imagine the user has typed in the following input in the console.
4141

42-
``` demo argumentOne "This is a qoute" --demo myFlagValue ```
42+
``` demo argumentOne "This is a qoute" --demo myOptionValue ```
4343

4444
### Raw
4545
The raw input as it was typed by the user in the Console.
@@ -49,16 +49,16 @@ The Id of the command it is the first argument that the user types, the id is th
4949
All input strings surrounded with " (quotation mark) in this example it is one quote with the value **"This is a quote"** (This value will be returned by the **SingleQuote** property)
5050
### Arguments
5151
All input strings not surrounded with " except for the first one (wich is the Identifier) and every argument starting with -- marks in the example it is one argument with the value **argumentOne** (This value will be returned by the **SingleArgument** property)
52-
### Flags
53-
All arguments that is staring with the -- marks is considered as flags, and ever argument after the flag is considered as that flags value, in the example the flag **demo** has the value **myFlagValue** a flag must not have a value.
52+
### Options
53+
All arguments that is staring with the -- marks is considered as options, and ever argument after the option is considered as that options value, in the example the option **demo** has the value **myOptionValue** a option must not have a value.
5454
### Path
5555
The path is a special value if your command only should have an input that is a path, then it is usefull, you do not need to input the path in quotation marks even if it contains blank space.
5656

5757
Read more about:
5858

5959
[Design your Command](Design_command.md)
6060

61-
[Flags](Flags.md)
61+
[Options](Options.md)
6262

6363
[PowerCommands Attribute](PowerCommandAttribute.md)
6464

Docs/Options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Options is what the name implies, options for your command, lets have a look at
55

66
You could also se that this Command has two options separated with pipe **"mode|name"**, first one named **mode** and the other one is **name**. This will give the user autocomplete feedback when typing - and using the [Tab] tangent.
77

8-
Programatically you can use Options in two ways, you could grab the value, wich is the parameter typed after the flag, like this (using the RegressionCommand as example, it is a user created command).
8+
Programatically you can use Options in two ways, you could grab the value, wich is the parameter typed after the option, like this (using the RegressionCommand as example, it is a user created command).
99

1010
``` regression --mode normal --name "My sample project" ```
1111

Docs/PowerCommandDesignAttribute.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This is easy with the usage of the PowerCommandsAttribute, just apply them on th
55

66
Now lets take a practical example...
77
## Use case
8-
You want to create a simple Command that converts a yaml file to json or xml format. Your choose to solve this with one Command that handles both this formats, you will use flags. You can read more about how the class will look like here: [Design your command](Design_command.md)
8+
You want to create a simple Command that converts a yaml file to json or xml format. Your choose to solve this with one Command that handles both this formats, you will use options. You can read more about how the class will look like here: [Design your command](Design_command.md)
99

1010
This is how the PowerCommandAttribute look like, to help the user consume this command.
1111

@@ -15,7 +15,7 @@ When the user running this applikcation and wants to now more about the Convert
1515

1616
```describe convert```
1717

18-
Or use the help flag
18+
Or use the help option
1919
```convert --help```
2020

2121
And this help will be displayed:
@@ -25,15 +25,15 @@ And this help will be displayed:
2525
### A clooser look on the syntax
2626
```
2727
[PowerCommandDesign( description: "Converting yaml format to json or xml format",
28-
flags: "!path|format",
28+
options: "!path|format",
2929
example: "//Convert to json format|convert --path \"c:\\temp\\test.yaml\" --format json|//Convert to xml format|convert --path \"c:\\temp\\test.yaml\" --format xml")]
3030
```
3131
The user can use this command like this (note that argument and quotes are not described in the attribute beacause this command do not use them):
3232

3333
![Alt text](images/Command_line_input_described.png?raw=true "Describe convert command")
3434

35-
## Mark argument, quote, flag or secret as required with **!** character
36-
If you look close at the example above you see two **flags** are declared like this **!path** and **format** the **!** character before the flag name tells the Core Runtime that this flag requires a value and it will be validated before the command Run methods executes, if he user ommits the **path** flag value this will occur:
35+
## Mark argument, quote, option or secret as required with **!** character
36+
If you look close at the example above you see two **options** are declared like this **!path** and **format** the **!** character before the option name tells the Core Runtime that this option requires a value and it will be validated before the command Run methods executes, if he user ommits the **path** option value this will occur:
3737

3838
![Alt text](images/convert_validation_error.png?raw=true "Describe convert command")
3939

@@ -44,9 +44,9 @@ Describe your arguments, separate them with | use // to display a commented line
4444
Describe your quotes, separate them with | use // to display a commented line over the actual quote.
4545
### suggestion
4646
Suggestion will be added to the autocomplete functionallity so the user could use tab to cycle trough the commands and commands with a suggested argument.
47-
### flags
48-
Describe your flags, separate them with | use // to display a commented line over the actual flag, all flags that are described will also be used by the autocomplete functionallity to help the user find the right flag.
49-
Read more about [Flags](Flags.md).
47+
### Options
48+
Describe your options, separate them with | use // to display a commented line over the actual option, all options that are described will also be used by the autocomplete functionallity to help the user find the right option.
49+
Read more about [options](options.md).
5050
### secrets
5151
Describe your secrets that the commands needs, you probably want to declare a secret as required with **!** character, in the sample above secret **cnDatabase** is marked as required.
5252
```
@@ -59,7 +59,7 @@ Read more about how to manage [Secrets](Secrets.md).
5959
Describe examples on how to use the command, separate them with | use // to display a commented line over the actual example.
6060

6161
### Separator and comments
62-
Flags, quotes, arguments and example all have a property on the PowerCommandAttribute, each item are separeted with | and if you want to put a comment row before your item add this with the prefix //, if you look at the example it is used to describe two examples of usage.
62+
options, quotes, arguments and example all have a property on the PowerCommandAttribute, each item are separeted with | and if you want to put a comment row before your item add this with the prefix //, if you look at the example it is used to describe two examples of usage.
6363

6464
example: "**//Convert to json format**|convert --path \"c:\\temp\\test.yaml\" --format json|**//Convert to xml format**|convert --path \"c:\\temp\\test.yaml\"
6565

@@ -71,6 +71,6 @@ Read more about:
7171

7272
[Input](Input.md)
7373

74-
[Flags](Flags.md)
74+
[options](options.md)
7575

7676
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)

Docs/PowerCommands Design Principles And Guidlines.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* [Use Markdown format](#UseMarkdownformat)
3030
* [Always describe your PowerCommands](#AlwaysdescribeyourPowerCommands)
3131
* [Use PowerCommand attribute](#UsePowerCommandattribute)
32-
* [Flags](#Flags)
32+
* [options](#options)
3333

3434
<!-- vscode-markdown-toc-config
3535
numbering=false
@@ -192,13 +192,13 @@ You have two options
192192
```powercommand update``` and then reload the solution
193193

194194
## <a name='DesignofyourCommands'></a>Design of your Commands
195-
Think of your command as an one line command with some parameters in a cmd prompt environment, it should do a single isolated task, for example lets say you want to convert yaml file to json or xml. A good name could be **ConvertCommand**, as parameters you have a path to the input file, and a flag for the format and a value to that flag. That is a pretty good design for one Command.
195+
Think of your command as an one line command with some parameters in a cmd prompt environment, it should do a single isolated task, for example lets say you want to convert yaml file to json or xml. A good name could be **ConvertCommand**, as parameters you have a path to the input file, and a option for the format and a value to that option. That is a pretty good design for one Command.
196196

197197
The usage of this command will look like this if I want to convert my yaml fil to json.
198198

199199
```convert "C:\temp\myYaml.yaml" --format json```
200200

201-
If you want the input to be more self described, which the framework encourages you to do for clarity, you can choose to add a flag for the filepath like this:
201+
If you want the input to be more self described, which the framework encourages you to do for clarity, you can choose to add a option for the filepath like this:
202202

203203
```convert --file "C:\temp\myYaml.yaml" --format json```
204204

@@ -332,14 +332,14 @@ In such cases they should support the identical configuration structure otherwis
332332
This is an example where every property of the attributes is used
333333

334334
![Alt text](images/attributes.png?raw=true "Attributes")
335-
Attributes is used to show a nice description of the command with the built in --help flag.
335+
Attributes is used to show a nice description of the command with the built in --help option.
336336

337337
```
338338
regression --help
339339
```
340-
![Alt text](images/power_command_attribute.png?raw=true "Usage of help flag")
340+
![Alt text](images/power_command_attribute.png?raw=true "Usage of help option")
341341

342-
But it is just not for displaying the help, the flag property and the suggestion property of the PowerCommandAttribute controls suggestions provided by intellisense, you should really take advantage of that.
342+
But it is just not for displaying the help, the option property and the suggestion property of the PowerCommandAttribute controls suggestions provided by intellisense, you should really take advantage of that.
343343

344344
## <a name='Options'></a>Options
345345
In the example image showing usage of the attributes you could se that the options: property is set to **"mode|name"**, that means that this command has two option one named **mode** and the other one is **name**. This will give the user autocomplete feedback when typing - and using the [Tab] tangent.

0 commit comments

Comments
 (0)