Skip to content

Commit

Permalink
grrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpchen committed Nov 14, 2024
1 parent 19ff204 commit 1dfb754
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Mediator

Facilitates communications between components.

## Motivation

- Communications between clients on any presence or absence. Like a chatroom or online games.

So mediator usually as a central facility to handle communications from different clients, clients are not required to know each other.
60 changes: 60 additions & 0 deletions docs/document/Powershell/docs/Alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Alias

## Set an Alias

```ps1
New-Alias <alias> <cmd_name>
```

> [!note]
> `New-Alias` throws when the alias already exist while `Set-Alias` will overrides it.
## Override an Alias

```ps1
Set-Alias <alias> <cmd_name>
```

## Checkout Alias

- Check out by alias

```ps1
Get-Alias <alias>
```

Or use `Get-Command`

```ps1
Get-Command <alias>
```

- Check out by command name

```ps1
Get-Alias -Definition <cmd_name>
```

## Builtin Aliases

Powershell ships with some builtin aliases, checkout by this command:

```ps1
Get-Alias | Where-Object { $_.Options -match 'ReadOnly|Constant' }
```

> [!note]
> Do not use custom aliases for public repository.
## Differ from Bash

Alias in powershell is only a name alias for a command, it can never take any predetermined parameters or flags like in bash.

```sh
alias gl='git log' # fine
```

```ps1
New-Alias gl 'git log' # not allowed! # [!code error]
```

4 changes: 4 additions & 0 deletions docs/document/Powershell/docs/Overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Overview

- Dynamic typing
- Case insensitive
Empty file.
Empty file.
Empty file.
50 changes: 45 additions & 5 deletions docs/document/Powershell/docs/Powershell as a Language/Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@

## Parameter

There's no positional parameters, it's a table-like definition, can be specified with any order.
Parameters are wrapped inside a function block with `param(...)`

```ps1
function Foo {
param (
[string]$foo
$Foo
)
}
```

> [!NOTE]
>
> Default type of a parameter is `System.Object`.
### Positional Parameter

Positional parameters allows passing values with explicit names.

```ps1
function Foo {
param (
[string] $Foo,
[string] $Bar
)
Write-Output "$Foo $Bar"
}
Foo -Foo foo -Bar bar
Foo foo bar # it's the same # [!code highlight]
```

### Default Parameter

```ps1
Expand All @@ -32,13 +53,13 @@ While `switch` will remain `$false` when unspecified.
```ps1
function Foo {
param (
[switch]$foo
[bool]$bar
[switch]$Foo
[bool]$Bar
)
}
# this is why we should use `switch` instead.
Foo -foo -bar $true # [!code highlight]
Foo -Foo -Bar $true # [!code highlight]
```

### Required Parameter
Expand All @@ -52,6 +73,25 @@ param (
)
```

### Parameter Alias

Parameters can have aliases. It's not needed for most of time though since pwsh can distinguish option by leading string.

```ps1
function Person {
param (
[Alias("n")] # [!code highlight]
[string]$Name,
[Alias("a")] # [!code highlight]
[int]$Age
)
Write-Host "Name: $Name, Age: $Age"
}
Person -n "Alice" -a 30 # [!code highlight]
```

## Lifetime

- Function should be define before it was called.
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions docs/document/Powershell/docs/Terminology & Naming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#

## Terminology

Powershell has its own terminologies besides other shells like bash.
It's a shell integrated with .NET, it's not a independent platform.

- `cmdlet`: builtin utils inside powershell, implemented using other languages like `C#`.
- `function`: a command implemented using powershell language itself.
- `application`: external executables.

0 comments on commit 1dfb754

Please sign in to comment.