doc: update the cross-platform shell scripts section (#8791)
parent
adf2aa8760
commit
5243c5adce
43
doc/docs.md
43
doc/docs.md
|
@ -3827,29 +3827,42 @@ The advantage of using V for this is the simplicity and predictability of the la
|
||||||
cross-platform support. "V scripts" run on Unix-like systems as well as on Windows.
|
cross-platform support. "V scripts" run on Unix-like systems as well as on Windows.
|
||||||
|
|
||||||
Use the `.vsh` file extension. It will make all functions in the `os`
|
Use the `.vsh` file extension. It will make all functions in the `os`
|
||||||
module global (so that you can use `ls()` instead of `os.ls()`, for example).
|
module global (so that you can use `mkdir()` instead of `os.mkdir()`, for example).
|
||||||
|
|
||||||
|
An example `deploy.vsh`:
|
||||||
```v wip
|
```v wip
|
||||||
#!/usr/local/bin/v run
|
|
||||||
// The shebang above associates the file to V on Unix-like systems,
|
// The shebang above associates the file to V on Unix-like systems,
|
||||||
// so it can be run just by specifying the path to the file
|
// so it can be run just by specifying the path to the file
|
||||||
// once it's made executable using `chmod +x`.
|
// once it's made executable using `chmod +x`.
|
||||||
|
|
||||||
rm('build/*')?
|
// Remove if build/ exits, ignore any errors if it doesn't
|
||||||
// Same as:
|
rmdir_all('build') or { }
|
||||||
files_build := ls('build/')?
|
|
||||||
for file in files_build {
|
|
||||||
rm(file)?
|
|
||||||
}
|
|
||||||
|
|
||||||
mv('*.v', 'build/')?
|
// Create build/, never fails as build/ does not exist
|
||||||
// Same as:
|
mkdir('build') ?
|
||||||
files := ls('.')?
|
|
||||||
for file in files {
|
// Move *.v files to build/
|
||||||
if file.ends_with('.v') {
|
result := exec('mv *.v build/') ?
|
||||||
mv(file, 'build/')?
|
if result.exit_code != 0 {
|
||||||
}
|
println(result.output)
|
||||||
}
|
}
|
||||||
|
// Similar to:
|
||||||
|
// files := ls('.') ?
|
||||||
|
// mut count := 0
|
||||||
|
// if files.len > 0 {
|
||||||
|
// for file in files {
|
||||||
|
// if file.ends_with('.v') {
|
||||||
|
// mv(file, 'build/') or {
|
||||||
|
// println('err: $err')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// count++
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if count == 0 {
|
||||||
|
// println('No files')
|
||||||
|
// }
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can either compile this like a normal V program and get an executable you can deploy and run
|
Now you can either compile this like a normal V program and get an executable you can deploy and run
|
||||||
|
|
Loading…
Reference in New Issue