1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tools: add v share file.v (#17172)

This commit is contained in:
Christopher Fore 2023-01-31 13:36:17 -05:00 committed by GitHub
parent 26b9464f51
commit 10261c427f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 0 deletions

39
cmd/tools/vshare.v Normal file
View File

@ -0,0 +1,39 @@
module main
import net.http
import os
import clipboard
fn main() {
mut cb := clipboard.new()
if os.args.len < 3 {
eprintln('Please provide a file')
exit(1)
}
if os.file_ext(os.args[2]) != '.v' {
eprintln('Must be a V source file.')
exit(1)
}
if !os.is_file(os.args[2]) {
eprintln('File not found.')
exit(1)
}
to_send := os.args[2]
content := os.read_file(to_send) or {
eprintln(err)
exit(1)
}
share := http.post_form('https://play.vlang.io/share', {
'code': content
})!
url := 'https://play.vlang.io/p/${share.body}'
cb.copy(url)
println(url)
}

View File

@ -34,6 +34,7 @@ const (
'self',
'setup-freetype',
'shader',
'share',
'should-compile-all',
'symlink',
'scan',

View File

@ -19,6 +19,8 @@ Other less frequently used commands supported by V include:
setup-freetype Setup thirdparty freetype on Windows.
share Send your code to the V Playground
translate Translate C code to V.
tracev Produce a tracing version of the v compiler.

View File

@ -0,0 +1,4 @@
Send your code to the V Playground
Usage:
v share FILE