init
This commit is contained in:
8
.editorconfig
Normal file
8
.editorconfig
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.v]
|
||||||
|
indent_style = tab
|
8
.gitattributes
vendored
Normal file
8
.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
* text=auto eol=lf
|
||||||
|
*.bat eol=crlf
|
||||||
|
|
||||||
|
*.v linguist-language=V
|
||||||
|
*.vv linguist-language=V
|
||||||
|
*.vsh linguist-language=V
|
||||||
|
v.mod linguist-language=V
|
||||||
|
.vdocignore linguist-language=ignore
|
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
main
|
||||||
|
code
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Ignore binary output folders
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# Ignore common editor/system specific metadata
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.iml
|
||||||
|
|
||||||
|
# ENV
|
||||||
|
.env
|
||||||
|
|
||||||
|
# vweb and database
|
||||||
|
*.db
|
||||||
|
*.js
|
46
shell.v
Normal file
46
shell.v
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
module shell
|
||||||
|
|
||||||
|
import strings.textscanner
|
||||||
|
|
||||||
|
const safe_chars = '%+,-./0123456789:=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'
|
||||||
|
|
||||||
|
// quote returns a shell-escaped version of string `s`.
|
||||||
|
pub fn quote(s string) string {
|
||||||
|
if s == '' {
|
||||||
|
return "''"
|
||||||
|
}
|
||||||
|
if s.is_pure_ascii() && s.contains_only(safe_chars) {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return "'" + s.replace("'", '\'"\'"\'') + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
// join joins `s` array members into a shell-escaped string.
|
||||||
|
pub fn join(s []string) string {
|
||||||
|
mut quoted_args := []string{}
|
||||||
|
for arg in s {
|
||||||
|
quoted_args << quote(arg)
|
||||||
|
}
|
||||||
|
return quoted_args.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
// // join_all joins their arguments into a shell-escaped string.
|
||||||
|
// pub fn join_all(s ...string) string {
|
||||||
|
// return join(s)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// split splits the string `s` into array using shell-like syntax.
|
||||||
|
pub fn split(s string) []string {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Lexer {
|
||||||
|
pub:
|
||||||
|
posix_mode bool = true
|
||||||
|
comment_chars string = '#'
|
||||||
|
pub mut:
|
||||||
|
tokens []string
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (mut x Lexer) process(s string) {
|
||||||
|
}
|
9
shell_test.v
Normal file
9
shell_test.v
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import shell
|
||||||
|
|
||||||
|
fn test_quote() {
|
||||||
|
assert shell.quote("janna d'arc") == '\'janna d\'"\'"\'arc\''
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_join() {
|
||||||
|
assert shell.join(['sh', '-c', 'hostname -f']) == "sh -c 'hostname -f'"
|
||||||
|
}
|
Reference in New Issue
Block a user