1 | new file mode 100644 |
2 | +module main |
3 | + |
4 | +import net.http |
5 | +import os |
6 | +import clipboard |
7 | + |
8 | +fn main() { |
9 | + mut cb := clipboard.new() |
10 | + |
11 | + if os.args.len < 3 { |
12 | + eprintln('Please provide a file') |
13 | + exit(1) |
14 | + } |
15 | + |
16 | + if os.file_ext(os.args[2]) != '.v' { |
17 | + eprintln('Must be a V source file.') |
18 | + exit(1) |
19 | + } |
20 | + |
21 | + if !os.is_file(os.args[2]) { |
22 | + eprintln('File not found.') |
23 | + exit(1) |
24 | + } |
25 | + |
26 | + to_send := os.args[2] |
27 | + |
28 | + content := os.read_file(to_send) or { |
29 | + eprintln(err) |
30 | + exit(1) |
31 | + } |
32 | + |
33 | + share := http.post_form('https://play.vlang.io/share', { |
34 | + 'code': content |
35 | + })! |
36 | + url := 'https://play.vlang.io/p/${share.body}' |
37 | + |
38 | + cb.copy(url) |
39 | + println(url) |
40 | +} |
41 | |