You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
4
5
5
The usage of this command will look like this if I want to convert my yaml fil to json.
6
6
7
7
```convert "C:\temp\myYaml.yaml" --format json```
8
8
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:
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.
14
14
15
15
## Example code
16
16
### 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.
18
18
19
19
```
20
20
using PainKiller.PowerCommands.Core.Extensions;
@@ -23,23 +23,23 @@ using PainKiller.PowerCommands.MyExampleCommands.Configuration;
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.
40
40
```
41
41
[PowerCommandDesign( description: "Converting yaml format to json or xml format",
42
-
flags: "!path|format",
42
+
options: "!path|format",
43
43
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")]
44
44
```
45
45
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.
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.
55
55
56
56
## 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:
58
58
59
59
Next step is to understand the [Power Commands Design attribute](PowerCommandDesignAttribute.md)
60
60
@@ -65,6 +65,6 @@ Read more about:
65
65
66
66
[Input](Input.md)
67
67
68
-
[Flags](Flags.md)
68
+
[Options](Options.md)
69
69
70
70
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)
For this example let´s imagine the user has typed in the following input in the console.
41
41
42
-
``` demo argumentOne "This is a qoute" --demo myFlagValue```
42
+
``` demo argumentOne "This is a qoute" --demo myOptionValue```
43
43
44
44
### Raw
45
45
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
49
49
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)
50
50
### Arguments
51
51
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.
54
54
### Path
55
55
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.
Copy file name to clipboardExpand all lines: Docs/Options.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ Options is what the name implies, options for your command, lets have a look at
5
5
6
6
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.
7
7
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).
9
9
10
10
``` regression --mode normal --name "My sample project" ```
Copy file name to clipboardExpand all lines: Docs/PowerCommandDesignAttribute.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ This is easy with the usage of the PowerCommandsAttribute, just apply them on th
5
5
6
6
Now lets take a practical example...
7
7
## 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)
9
9
10
10
This is how the PowerCommandAttribute look like, to help the user consume this command.
11
11
@@ -15,7 +15,7 @@ When the user running this applikcation and wants to now more about the Convert
15
15
16
16
```describe convert```
17
17
18
-
Or use the help flag
18
+
Or use the help option
19
19
```convert --help```
20
20
21
21
And this help will be displayed:
@@ -25,15 +25,15 @@ And this help will be displayed:
25
25
### A clooser look on the syntax
26
26
```
27
27
[PowerCommandDesign( description: "Converting yaml format to json or xml format",
28
-
flags: "!path|format",
28
+
options: "!path|format",
29
29
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")]
30
30
```
31
31
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):
## 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:
@@ -44,9 +44,9 @@ Describe your arguments, separate them with | use // to display a commented line
44
44
Describe your quotes, separate them with | use // to display a commented line over the actual quote.
45
45
### suggestion
46
46
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).
50
50
### secrets
51
51
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.
52
52
```
@@ -59,7 +59,7 @@ Read more about how to manage [Secrets](Secrets.md).
59
59
Describe examples on how to use the command, separate them with | use // to display a commented line over the actual example.
60
60
61
61
### 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.
63
63
64
64
example: "**//Convert to json format**|convert --path \"c:\\temp\\test.yaml\" --format json|**//Convert to xml format**|convert --path \"c:\\temp\\test.yaml\"
65
65
@@ -71,6 +71,6 @@ Read more about:
71
71
72
72
[Input](Input.md)
73
73
74
-
[Flags](Flags.md)
74
+
[options](options.md)
75
75
76
76
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)
```powercommand update``` and then reload the solution
193
193
194
194
## <aname='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.
196
196
197
197
The usage of this command will look like this if I want to convert my yaml fil to json.
198
198
199
199
```convert "C:\temp\myYaml.yaml" --format json```
200
200
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:
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.
336
336
337
337
```
338
338
regression --help
339
339
```
340
-

340
+

341
341
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.
343
343
344
344
## <aname='Options'></a>Options
345
345
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