From 10261c427f0961e287c91b2b439ceea632cdba60 Mon Sep 17 00:00:00 2001 From: Christopher Fore Date: Tue, 31 Jan 2023 13:36:17 -0500 Subject: [PATCH] tools: add `v share file.v` (#17172) --- cmd/tools/vshare.v | 39 +++++++++++++++++++++++++++++++++++++ cmd/v/v.v | 1 + vlib/v/help/other/other.txt | 2 ++ vlib/v/help/other/share.txt | 4 ++++ 4 files changed, 46 insertions(+) create mode 100644 cmd/tools/vshare.v create mode 100644 vlib/v/help/other/share.txt diff --git a/cmd/tools/vshare.v b/cmd/tools/vshare.v new file mode 100644 index 000000000..9bf02ac89 --- /dev/null +++ b/cmd/tools/vshare.v @@ -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) +} diff --git a/cmd/v/v.v b/cmd/v/v.v index 0d377a46d..9213d6dde 100755 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -34,6 +34,7 @@ const ( 'self', 'setup-freetype', 'shader', + 'share', 'should-compile-all', 'symlink', 'scan', diff --git a/vlib/v/help/other/other.txt b/vlib/v/help/other/other.txt index 7ca92f38c..44671919c 100644 --- a/vlib/v/help/other/other.txt +++ b/vlib/v/help/other/other.txt @@ -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. diff --git a/vlib/v/help/other/share.txt b/vlib/v/help/other/share.txt new file mode 100644 index 000000000..f868bfdf7 --- /dev/null +++ b/vlib/v/help/other/share.txt @@ -0,0 +1,4 @@ +Send your code to the V Playground + +Usage: + v share FILE \ No newline at end of file -- 2.30.2