Last active
March 18, 2024 21:26
-
-
Save adrianmgg/5d14a0a0aa465328952efa8d00541d96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
quickly initialize a new rust project tailored for doing quick temporary testing of stuff | |
.PARAMETER ProjectTemplate | |
one of: Bin, Lib | |
.PARAMETER OpenInVSCode | |
open created project in a new vscode window | |
.EXAMPLE | |
PS> create_temp_rust_project | |
.EXAMPLE | |
PS> create_temp_rust_project -ProjectTemplate Bin -OpenInVSCode | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[switch]$OpenInVSCode, | |
[Parameter()] | |
[String] | |
[ValidateSet('Bin', 'Lib', IgnoreCase=$true)] | |
$ProjectTemplate = 'Bin', | |
[Parameter()] | |
[string]$Name = '' | |
) | |
$ErrorActionPreference = 'Stop' | |
# some hardcoded vars for where i keep my stuff | |
$ProjectsBaseDir = 'D:\code\rust' | |
enum ProjectTemplate { | |
Lib | |
Bin | |
} | |
# New-Variable ProjectTemplate ([ProjectTemplate]$ProjectTemplate) -Force | |
# create folder for it | |
$outdir = mkdir (join-path $ProjectsBaseDir "$(if($Name -ne '') { "$Name" } else { 'thing' })-$(get-date -format 'yyyyMMdd-HHmmss')") -ErrorAction Stop -Verbose | |
# | |
Push-Location $outdir -ErrorAction Stop -Verbose | |
cargo init . --vcs git $(switch([ProjectTemplate]$ProjectTemplate) { | |
Lib { '--lib' } | |
Bin { '--bin' } | |
Default { Write-Error "unexpected ProjectTemplate value: ($($ProjectTemplate))" } | |
}) $(if($Name -ne '') { | |
'--name'; $Name | |
}) | |
git config commit.gpgsign false | |
git add . | |
git commit -m 'initial commit (cargo init)' | |
if($OpenInVSCode) { | |
# code . | |
code --new-window . (gci ./src/ *.rs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment