Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windows) powershell and batch support #45

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
name: ${{ matrix.platform }}-build
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest]
steps:
- name: Checkout master
uses: actions/checkout@master
Expand All @@ -15,8 +19,12 @@ jobs:
run: cargo build --release --frozen

test:
name: Test
runs-on: ubuntu-latest
name: ${{ matrix.platform }}-test
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest]
steps:
- name: Checkout master
uses: actions/checkout@master
Expand All @@ -28,8 +36,12 @@ jobs:
run: cargo fetch
- name: Build in test mode
run: cargo build --tests --frozen
- name: Make mask available globally for certain test suites that depend on it
run: cp ./target/debug/mask /usr/share/rust/.cargo/bin
- name: Make mask available globally (windows)
run: copy ./target/debug/mask.exe ~/.cargo/bin/
if: matrix.platform == 'windows-latest'
- name: Make mask available globally (linux)
run: cp ./target/debug/mask ~/.cargo/bin
if: matrix.platform == 'ubuntu-latest'
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved
- name: Run tests
run: cargo test --frozen

Expand Down
61 changes: 60 additions & 1 deletion maskfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ else
fi
~~~

**Note:** On Windows platforms, `mask` falls back to running `powershell` code blocks.

~~~powershell
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved
param (
$maskfile_command = $env:maskfile_command,
$watch = $env:watch
)
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved

$cargo_cmd = "cargo run -- $maskfile_command"
$extra_args = "--exts rs --restart $cargo_cmd"

if ($watch) {
Start-Process watchexec -ArgumentList $extra_args -NoNewWindow -PassThru
} else {
cargo run -- $maskfile_command
}
~~~
jacobdeichert marked this conversation as resolved.
Show resolved Hide resolved


## build
Expand All @@ -37,7 +54,9 @@ fi
cargo build --release
~~~


~~~powershell
cargo build --release
~~~

## link

Expand All @@ -47,6 +66,9 @@ cargo build --release
cargo install --force --path .
~~~

~~~powershell
[Diagnostics.Process]::Start("cargo", "install --force --path .").WaitForExit()
~~~


## test
Expand Down Expand Up @@ -78,7 +100,26 @@ fi
echo "Tests passed!"
~~~

~~~powershell
param (
$file = $env:file
)
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved

$extra_args = ""
$verbose = $env:verbose

if ($verbose) {
$extra_args = "-- --nocapture --test-threads=1"
}

Write-Output "Running tests..."
if (!$file) {
cargo test $extra_args
} else {
cargo test --test $file $extra_args
}
Write-Output "Tests passed!"
~~~

## deps

Expand All @@ -92,6 +133,9 @@ echo "Tests passed!"
cargo update
~~~

~~~powershell
cargo update
~~~


## format
Expand All @@ -111,6 +155,17 @@ else
fi
~~~

~~~powershell
param (
$check = $env:check
)

if ($check) {
cargo fmt --all -- --check
} else {
cargo fmt
}
~~~


## lint
Expand All @@ -120,3 +175,7 @@ fi
~~~bash
cargo clippy
~~~

~~~powershell
cargo clippy
~~~
6 changes: 6 additions & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ fn prepare_command(cmd: &Command) -> process::Command {
child.arg("-r").arg(source);
child
}
#[cfg(windows)]
"cmd" | "batch" => {
let mut child = process::Command::new("cmd.exe");
child.arg("/c").arg(source);
child
}
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved
// Any other executor that supports -c (sh, bash, zsh, fish, dash, etc...)
_ => {
let mut child = process::Command::new(executor);
Expand Down
20 changes: 20 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ pub fn build_command_structure(maskfile_contents: String) -> Command {
}
current_command = Command::new(heading_level as u8);
}
#[cfg(not(windows))]
Tag::CodeBlock(lang_code) => {
if lang_code.to_string() != "powershell"
&& lang_code.to_string() != "batch"
&& lang_code.to_string() != "cmd"
{
current_command.script.executor = lang_code.to_string();
}
}
#[cfg(windows)]
tensor-programming marked this conversation as resolved.
Show resolved Hide resolved
Tag::CodeBlock(lang_code) => {
current_command.script.executor = lang_code.to_string();
}
Expand All @@ -52,6 +62,16 @@ pub fn build_command_structure(maskfile_contents: String) -> Command {
Tag::BlockQuote => {
current_command.desc = text.clone();
}
#[cfg(not(windows))]
Tag::CodeBlock(lang_code) => {
if lang_code.to_string() != "powershell"
&& lang_code.to_string() != "batch"
&& lang_code.to_string() != "cmd"
{
current_command.script.source = text.to_string();
}
}
#[cfg(windows)]
Tag::CodeBlock(_) => {
current_command.script.source = text.to_string();
}
Expand Down
73 changes: 73 additions & 0 deletions tests/arguments_and_flags_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ fn positional_arguments() {
~~~bash
echo "Testing $test_case in $file"
~~~

~~~powershell
param (
$test_case = $env:test_case,
$file = $env:file
)

Write-Output "Testing $test_case in $file"
~~~
"#,
);

Expand Down Expand Up @@ -64,6 +73,20 @@ else
echo $PORT
fi
```

```powershell
param (
[string]
[Parameter(Mandatory = $false)]
$port = $env:port
)

if ($env:verbose) {
Write-Output "Starting an http server on PORT: $port"
} else {
Write-Output $port
}
```
"#,
);

Expand Down Expand Up @@ -97,6 +120,16 @@ mod when_entering_negative_numbers {
~~~bash
echo $(($a + $b))
~~~

~~~powershell
param (
[int]$a = $env:a,
[int]$b = $env:b
)
$sum = "$($a + $b)"

Write-Output $sum
~~~
"#,
);

Expand Down Expand Up @@ -124,6 +157,16 @@ echo $(($a + $b))
~~~bash
echo $(($a + $b))
~~~

~~~powershell
param (
[int]$a = $env:a,
[int]$b = $env:b
)
$sum = "$($a + $b)"

Write-Output $sum
~~~
"#,
);

Expand Down Expand Up @@ -152,6 +195,13 @@ mod numerical_option_flag {
~~~bash
echo "Value: $val"
~~~

~~~powershell
param (
$in = $env:val
)
Write-Output "Value: $in"
~~~
"#,
);

Expand All @@ -176,6 +226,14 @@ echo "Value: $val"
~~~bash
echo "Value: $val"
~~~

~~~powershell
param (
[int]$in = $env:val
)

Write-Output "Value: $in"
~~~
"#,
);

Expand All @@ -200,6 +258,13 @@ echo "Value: $val"
~~~bash
echo "Value: $val"
~~~

~~~powershell
param (
[Double]$in = $env:val
)
Write-Output "Value: $in"
~~~
"#,
);

Expand All @@ -224,6 +289,10 @@ echo "Value: $val"
~~~bash
echo "This shouldn't render"
~~~

~~~powershell
Write-Output "This shouldn't render"
~~~
"#,
);

Expand Down Expand Up @@ -251,6 +320,10 @@ echo "This shouldn't render"
~~~bash
echo "No arg this time"
~~~

~~~powershell
Write-Output "No arg this time"
~~~
"#,
);

Expand Down
Loading