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
# Read, Write and navigate to files and directories
2
+
3
+
From version 1.0.4.0 of PowerCommands you can call two commands using one line, using the | character, at the moment it is limited to two commands but the plan is to allow as many commands as you like in a call chain.
4
+
5
+
The code below shows an example on how it could be used, in this case I first run the command `output` which is a really simple command that prints out what you input in the flag `--text`, then we use the | to let the runtime know that one more command should be run, in this case it is the file command, I am adding a --target flag with a file name.
6
+
7
+

8
+
9
+
## Handling the output from the previous command
10
+
The target command must implement code to work as a target command, let´s take a look on how this is implemented in the FileCommand class.
11
+
12
+

13
+
14
+
The first row shows how a command can grab the result from the previous command.
As you could see there are helper methods and the important properties Configuration and Input. Input is cruisal for the Run methods without access to the Input, your code is "blind" and could only do static things that ignores the console input. The helper methods is for creating the return result for the Run methods and other helper is for [output](ConsoleOutput.md) to the console.
22
+
As you could see there are helper methods and the important properties Configuration and Input. Input is crucial for the Run methods without access to the Input, your code is "blind" and could only do static things that ignores the console input. The helper methods is for creating the return result for the Run methods and other helper is for [output](ConsoleOutput.md) to the console.
23
23
24
24
## Create your own BaseCommand
25
25
26
-
There are many use cases where it makes sense to create a base class for your other commands in your CLI applikation, lets say that you always need access to a keyvault and you do not want to repeat that code in every command you do. Here are som guidelines to help you.
26
+
There are many use cases where it makes sense to create a base class for your other commands in your CLI application, lets say that you always need access to a keyvault and you do not want to repeat that code in every command you do. Here are som guidelines to help you.
27
27
- The name should not end with Command, some examples on good naming could be VaultCommandBase or EntityFrameworkCommandBase
28
28
- If the class only is used to be inherited by other commands, it is good ide to declare it as an abstract class.
29
29
- Let your base class implement CommandBase, that way you have all the helpers methods.
@@ -32,6 +32,6 @@ There are many use cases where it makes sense to create a base class for your ot
32
32
33
33
[Design your Command](Design_command.md)
34
34
35
-
[Output to the Console guidline](ConsoleService.md)
35
+
[Output to the Console guideline](ConsoleService.md)
36
36
37
37
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)
### Using the Write helper methods in the [CommandBase](CommandBase.md) class
7
7
- WriteCritical
8
-
-WriteWarnig
8
+
-WriteWarning
9
9
- WriteError
10
10
- WriteLine
11
11
- and so on...
12
12
13
13
## Why?
14
-
The output will be displayed in a decided way, warnings wil have a certain color, diffrent from errors, and the output will be logged by default. And they will have log level corresponding to the type of output. WriteLine and Write have the options to be printed out to the console without being logged.
14
+
The output will be displayed in a decided way, warnings wil have a certain color, different from errors, and the output will be logged by default. And they will have log level corresponding to the type of output. WriteLine and Write have the options to be printed out to the console without being logged.
15
15
16
16
### Exceptions
17
-
There are situations where Console.Write or WriteLine is usefull, if you want to be sure that it will not be logged by misstake, the output of secrets for instance.
17
+
There are situations where Console.Write or WriteLine is useful, if you want to be sure that it will not be logged by mistake, the output of secrets for instance.
Do not worry about all the drama that an empty demo input creates, the **demo** command demonstrates how you can use options to design your command and achive validation without the need for you to add validation code.
21
+
Do not worry about all the drama that an empty demo input creates, the **demo** command demonstrates how you can use options to design your command and achieve validation without the need for you to add validation code.
22
22
The demo command has an design attribute that looks something like this:
Copy file name to clipboardExpand all lines: Docs/Customize.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,11 @@
3
3
In your PowerCommands solution you have free hands to build you excellent CLI application, using the Core Framework together with your own homebrew code and code from others.
4
4
Here is good things you need to know and think about.
5
5
6
-
- Do not change code in the Core, use the recommended customizeble area insted, if you do change the core you may break compability and can not use the update functionallity because that will overwrite your changes.
7
-
- If your business logic is generall and could be reused by many Commands projekct and maybe by other people, build a Custom Component.
8
-
- In the bootstap project you can change some basic behaviour if you want.
6
+
- Do not change code in the Core, use the recommended customizable area instead, if you do change the core you may break compatibility and can not use the update functionality because that will overwrite your changes.
7
+
- If your business logic is general and could be reused by many Commands projekct and maybe by other people, build a Custom Component.
8
+
- In the bootstrap project you can change some basic behavior if you want.
9
9
- In the Commands project you can customize and extend the Configuration used by your Commands.
10
-
- The class **PowerCommandServices.cs** loads basic services like the logging, the runtime and diagnostic handlar, here is the place to swap them if you feeling brave and adventurous.
10
+
- The class **PowerCommandServices.cs** loads basic services like the logging, the runtime and diagnostic handler, here is the place to swap them if you feeling brave and adventurous.
11
11
-**Startup.cs** is a good place to add code that you will run when the application starts.
12
12
-**Program.cs** is the main entry for the application, feel free to add stuff here, se example below.
13
13
@@ -29,7 +29,7 @@ manager.Run(args);
29
29
```
30
30
## One more example, tweak the code completion preload of values.
31
31
32
-
Open the **PowerCommandServices.cs** and you will find this code, where the codecompletion loads with name of the commands and existing suggestion defined in the [PowerCommandAttribute](PowerCommandAttribute.md)
32
+
Open the **PowerCommandServices.cs** and you will find this code, where the code completion loads with name of the commands and existing suggestion defined in the [PowerCommandAttribute](PowerCommandAttribute.md)
33
33
34
34
```
35
35
var suggestions = new List<string>(Runtime.CommandIDs);
@@ -41,6 +41,6 @@ Read more about:
41
41
42
42
[Extend your configuration](ExtendYourConfiguration.md)
43
43
44
-
[Design principles and guidlines](PowerCommands%20Design%20Principles%20And%20Guidlines.md)
44
+
[Design principles and guidelines](PowerCommands%20Design%20Principles%20And%20Guidlines.md)
45
45
46
46
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)
Copy file name to clipboardExpand all lines: Docs/Design_command.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ There are other ways you can solve the design to, you can solve it with two Comm
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 [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.
17
+
You want a simple Command that converts a yaml file to json or xml format. Your first architecture decision is, one command or two? Well, it is a matter of taste but for this example the choice 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;
@@ -45,7 +45,7 @@ The new design look like this.
45
45
options: "!PATH|format",
46
46
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")]
47
47
```
48
-
Have a closer look at the !PATH option, it starts with a **!** and it consists of upperletter cases only **PATH**, with the use of the **!**sympol the option must have a value. With the use of uppercase letter the option it self is **mandatory**.
48
+
Have a closer look at the !PATH option, it starts with a **!** and it consists of upper letter cases only **PATH**, with the use of the **!**symbol the option must have a value. With the use of uppercase letter the option it self is **mandatory**.
49
49
50
50
If I run the command empty I trigger a validation error.
51
51
@@ -56,7 +56,7 @@ 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 options named **path** and **format** to handle progamatically to create a file on the given path with the given format.
59
+
This input will first be handled by the Core Framework, using the Identifier an instance of the ConvertCommand will be created and the framework will also add the [Input](Input.md) instance to the ConvertCommand instance which give your convert command two options named **path** and **format** to handle programmatically to create a file on the given path with the given format.
60
60
61
61
# An alternative design using suggestions
62
62
Instead of using the option **format** in the previous example you could use argument **xml** and **json** instead, there is nothing wrong or right here, it is up to you to choose what you think is the best approach.
@@ -94,10 +94,10 @@ public class ConvertCommand : CommandBase<PowerCommandsConfiguration>
94
94
}
95
95
}
96
96
```
97
-
### **Please Note** that the name of the arguments in the design attribute is not important in code, it is usefull thou when help about the command is displayed. Suggestions is what it sounds like only suggestions to guide the user to the right input.
97
+
### **Please Note** that the name of the arguments in the design attribute is not important in code, it is useful thou when help about the command is displayed. Suggestions is what it sounds like only suggestions to guide the user to the right input.
98
98
99
99
## Must I use the PowerCommandDesign attribute on every command I create?
100
-
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.
100
+
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, which 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.
101
101
102
102
Read more about CLI design here: [10 design principles for delightful CLIs](https://blog.developer.atlassian.com/10-design-principles-for-delightful-clis/)
Copy file name to clipboardExpand all lines: Docs/DocumentationIndexDB.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
# Documentation Index DB
2
2
3
3
The Core framework uses a very simple Documentation Index that is stored as an json file named **DocsDB.data** in the **%USERNAME%\AppData\Roaming\PowerCommands** directory.
4
-
You could also add new entries to this index if you want, prefered way is to use the **[DocCommand](https://github.com/PowerCommands/PowerCommands2022/blob/main/src/PainKiller.PowerCommands/PainKiller.PowerCommands.MyExampleCommands/Commands/DocCommand.cs)** and use this command.
4
+
You could also add new entries to this index if you want, preferred way is to use the **[DocCommand](https://github.com/PowerCommands/PowerCommands2022/blob/main/src/PainKiller.PowerCommands/PainKiller.PowerCommands.MyExampleCommands/Commands/DocCommand.cs)** and use this command.
5
5
6
-
The example adds a new Doc instans to the DocsDB with a link to google and some tags to it.
6
+
The example adds a new Doc instance to the DocsDB with a link to google and some tags to it.
The DescribeCommand uses this DocsDB to find help for you, if you type anything that matches the name or a tag the application will open that URL for you, every page in this github documentation is added to this index.
13
13
14
14
## Update the DocsDB Index
15
-
Easiest way is to start the applicatin from the bin folder, and use this command
15
+
Easiest way is to start the application from the bin folder, and use this command
16
16
```
17
17
powercommands update
18
18
```
19
19
20
-
If you run the same command while debugging in Visual Studio the whole Core Framwork will be updated. (no harm doing that but you need to be aware of it)
20
+
If you run the same command while debugging in Visual Studio the whole Core Framework will be updated. (no harm doing that but you need to be aware of it)
21
21
The update will merge the content of your local stored file with the file on Github, so you do not lose your own added Docs.
0 commit comments