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 (fix mac) #58

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ee8e0a
add batch scripting for windows
tensor-programming Mar 6, 2020
d96379c
add powershell scripts to maskfile
tensor-programming Mar 6, 2020
0a96655
update tests
tensor-programming Mar 6, 2020
355da3b
add powershell test to runtime
tensor-programming Mar 6, 2020
fc5a697
update maskfile
tensor-programming Mar 6, 2020
c524801
ignore powershell on non windows platforms
tensor-programming Mar 6, 2020
68b29b7
filter powershell, batch and cmd on linux
tensor-programming Mar 6, 2020
e8702f3
fix bitor
tensor-programming Mar 6, 2020
3e9987c
flip `or` to `and`.
tensor-programming Mar 6, 2020
9269ae4
test-action
tensor-programming Mar 6, 2020
4aa05ae
test-ci
tensor-programming Mar 6, 2020
290b9a3
Delete rust.yml
tensor-programming Mar 6, 2020
a11563e
add windows logic
tensor-programming Mar 6, 2020
b6b7769
Update ci.yml
tensor-programming Mar 6, 2020
2bb4554
add if statements
tensor-programming Mar 6, 2020
163870b
Update ci.yml
tensor-programming Mar 6, 2020
b897438
add github action for windows
tensor-programming Mar 6, 2020
fa3dd16
fix if stattements
tensor-programming Mar 6, 2020
dbd2101
fix spelling error
tensor-programming Mar 6, 2020
deed084
update powershell script and add cmd/batch tests
tensor-programming Mar 8, 2020
835a0a8
change write-host to write-output
tensor-programming Mar 8, 2020
485a3b0
update maskfile powershell
tensor-programming Mar 8, 2020
9a0c060
Update maskfile.md
tensor-programming Mar 20, 2020
eda8d5b
remove unnessecary env calls from powershell
tensor-programming Mar 20, 2020
a2f94ed
remove shortcase flags from powershell scripts.
tensor-programming Mar 22, 2020
dd13edf
Merge branch 'feat/windows-powershell-support' of https://github.com/…
tensor-programming Apr 15, 2020
f79ebd5
add mac support for CI
tensor-programming Apr 15, 2020
4d3c6a5
add macos to build
tensor-programming Apr 15, 2020
9dea707
trying adding a powershell specific flag
tensor-programming Apr 15, 2020
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
36 changes: 22 additions & 14 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, macos-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, macos-latest]
steps:
- name: Checkout master
uses: actions/checkout@master
Expand All @@ -28,16 +36,16 @@ 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'
- name: Make mask available globally (mac)
run: cp ./target/debug/mask ~/.cargo/bin
if: matrix.platform == 'macos-latest'
- name: Run tests
run: cargo test --frozen

format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@master
- name: Verify formatting is correct
run: cargo fmt --all -- --check
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you accidentally removed formatting from CI? I'll fix on master so i can get this merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I did. Woops, sorry about that.


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
param (
$maskfile_command = $env:maskfile_command,
$watch = $env:watch
)

$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
}
~~~


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

$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
~~~
12 changes: 12 additions & 0 deletions src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ 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
}
#[cfg(windows)]
"powershell" => {
let mut child = process::Command::new("powershell.exe");
child.arg("-c").arg(source);
child
}
// 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)]
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