Skip to content

Commit dc94a35

Browse files
committed
Version 1.0.4.0
1 parent d9ada63 commit dc94a35

File tree

89 files changed

+1284
-413
lines changed

Some content is hidden

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

89 files changed

+1284
-413
lines changed

Docs/ChainCommands.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# 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+
![Alt text](images/pipe_call.png?raw=true "Chain of commands")
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+
![Alt text](images/file_command.png?raw=true "Handling the output from the previous command")
13+
14+
The first row shows how a command can grab the result from the previous command.
15+
16+
```var latestCommandResult = IPowerCommandsRuntime.DefaultInstance?.Latest;```
17+
18+
If you want create a command that explore this, it could look like this.
19+
20+
```
21+
[PowerCommandDesign(description: "Run commands that supports pipe functionality.",
22+
example: "//First run this command and then the version command|version [PIPE] pipe")]
23+
public class PipeCommand(string identifier, PowerCommandsConfiguration configuration) : CdCommand(identifier, configuration)
24+
{
25+
public override RunResult Run()
26+
{
27+
Console.Clear();
28+
var result = IPowerCommandsRuntime.DefaultInstance?.Latest;
29+
if (result == null) return Ok();
30+
WriteLine($"Previous command: {result!.ExecutingCommand.Identifier}");
31+
WriteLine($"Previous output length: {result!.Output.Length}");
32+
WriteLine($"Previous command status: {result!.Status}");
33+
WriteLine($"Previous command input: {result!.Input.Raw}");
34+
var retVal = Ok();
35+
return retVal;
36+
}
37+
}
38+
```
39+
40+
Read more about:
41+
42+
[Read and write files with FileCommand](ReadWriteFileHandler.md)
43+
44+
[Design your Command](Design_command.md)
45+
46+
[Input](Input.md)
47+
48+
[PowerCommands Design Attribute](PowerCommandDesignAttribute.md)
49+
50+
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)

Docs/CommandBase.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CommandBase
22

3-
CommandBase is the base class for most of your Command classes, it has some pracical help classes that you could use in your Command classes.
3+
CommandBase is the base class for most of your Command classes, it has some practical help classes that you could use in your Command classes.
44

55
But before that lets have a look on the contract that all Commands must implement to work properly and... of course to even compile.
66

@@ -19,11 +19,11 @@ The Identifier and the InitializeRun will be used by the Core Framework, your wi
1919
## Class diagram
2020
![Alt text](images/CommandBase.png?raw=true "Command Base")
2121

22-
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.
2323

2424
## Create your own BaseCommand
2525

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.
2727
- The name should not end with Command, some examples on good naming could be VaultCommandBase or EntityFrameworkCommandBase
2828
- If the class only is used to be inherited by other commands, it is good ide to declare it as an abstract class.
2929
- 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
3232

3333
[Design your Command](Design_command.md)
3434

35-
[Output to the Console guidline](ConsoleService.md)
35+
[Output to the Console guideline](ConsoleService.md)
3636

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

Docs/Configuration.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ Here you declare those dll components that the Core framework will use to find a
2828
Environment variables that the application needs to be aware about.
2929

3030
## Log
31-
Details about the loggning.
31+
Details about the logging.
3232

3333
## Metadata
3434
Description about your PowerCommand project.
3535

3636
## Repository
37-
URL to this repsository, used internally to create new VS solutions and Commands using PowerCommands applikation.
37+
URL to this repository, used internally to create new VS solutions and Commands using PowerCommands application.
3838

3939
## Secret
40-
Name of secrets that the application needs to be aware about, each secret has an corrensponding environment value that is encrypted.
40+
Name of secrets that the application needs to be aware about, each secret has an corresponding environment value that is encrypted.
4141

4242
## ShowDiagnosticInformation
4343
Enable or disable the display of diagnostic output.

Docs/ConsoleOutput.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# Display output to the console
22
## ConsoleService
3-
The output to the Console should almout always use the ConsoleService to print output out to the console, this could be done in diffrent ways.
3+
The output to the Console should almout always use the ConsoleService to print output out to the console, this could be done in different ways.
44
### Using the static service directly
55
![Alt text](images/ConsoleService.png?raw=true "Console Service")
66
### Using the Write helper methods in the [CommandBase](CommandBase.md) class
77
- WriteCritical
8-
- WriteWarnig
8+
- WriteWarning
99
- WriteError
1010
- WriteLine
1111
- and so on...
1212

1313
## 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.
1515

1616
### 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.
1818

1919
Read more about:
2020

Docs/Create_new_ project.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ And this is what you should se!
1818

1919
![Alt text](images/DemoCommand.png?raw=true "Demo Command")
2020

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 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.
2222
The demo command has an design attribute that looks something like this:
2323

2424
```

Docs/Create_new_command.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## There is two ways of doing that, manually our let PowerCommand create one for you, using a template
44

55
### Manually
6-
Create a new class in the Commands directory or copy one existing and just rename it, a command that outputs "Hello World!" shoult look like this.
6+
Create a new class in the Commands directory or copy one existing and just rename it, a command that outputs "Hello World!" should look like this.
77

88
```
99
[PowerCommand( description: "The Hello World classic!", example: "helloworld")]
@@ -19,7 +19,7 @@ public class HelloWorldCommand : CommandBase<PowerCommandsConfiguration>
1919
}
2020
```
2121

22-
When you start the PowerCommand applikcation and type
22+
When you start the PowerCommand application and type
2323
```
2424
helloworld
2525
```

Docs/Customize.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
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.
44
Here is good things you need to know and think about.
55

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.
99
- 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.
1111
- **Startup.cs** is a good place to add code that you will run when the application starts.
1212
- **Program.cs** is the main entry for the application, feel free to add stuff here, se example below.
1313

@@ -29,7 +29,7 @@ manager.Run(args);
2929
```
3030
## One more example, tweak the code completion preload of values.
3131

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)
3333

3434
```
3535
var suggestions = new List<string>(Runtime.CommandIDs);
@@ -41,6 +41,6 @@ Read more about:
4141

4242
[Extend your configuration](ExtendYourConfiguration.md)
4343

44-
[Design principles and guidlines](PowerCommands%20Design%20Principles%20And%20Guidlines.md)
44+
[Design principles and guidelines](PowerCommands%20Design%20Principles%20And%20Guidlines.md)
4545

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

Docs/Design_command.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ There are other ways you can solve the design to, you can solve it with two Comm
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 [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.
1818

1919
```
2020
using PainKiller.PowerCommands.Core.Extensions;
@@ -45,7 +45,7 @@ The new design look like this.
4545
options: "!PATH|format",
4646
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")]
4747
```
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**.
4949

5050
If I run the command empty I trigger a validation error.
5151

@@ -56,7 +56,7 @@ Lets have look of how the user input is designed.
5656

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

59-
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.
6060

6161
# An alternative design using suggestions
6262
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>
9494
}
9595
}
9696
```
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.
9898

9999
## 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.
101101

102102
Read more about CLI design here: [10 design principles for delightful CLIs](https://blog.developer.atlassian.com/10-design-principles-for-delightful-clis/)
103103

Docs/DialogService.md

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ var password = DialogService.SecretPromptDialog("Enter secret:");
4242
## QuestionAnswerDialog and YesNoDialog
4343
This dialog either prompt a question and returns the answer as an string or with the ```YesNoDialog``` prompts a question and returns a bool.
4444

45-
46-
47-
4845
Read more about:
4946

5047
[Design your Command](Design_command.md)

Docs/DocumentationIndexDB.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Documentation Index DB
22

33
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.
55

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.
77
```
88
doc "https://www.google.se/" --name Google-Search --tags tools,search,google
99
```
@@ -12,12 +12,12 @@ doc "https://www.google.se/" --name Google-Search --tags tools,search,google
1212
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.
1313

1414
## 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
1616
```
1717
powercommands update
1818
```
1919

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)
2121
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.
2222

2323
Read more about:

0 commit comments

Comments
 (0)