| 1 | module main |
| 2 | |
| 3 | import json |
| 4 | import net.http |
| 5 | import os |
| 6 | import vshare |
| 7 | |
| 8 | struct Response { |
| 9 | hash string |
| 10 | error string |
| 11 | } |
| 12 | |
| 13 | fn main() { |
| 14 | if os.args.len < 3 { |
| 15 | eprintln('Please provide a file') |
| 16 | exit(1) |
| 17 | } |
| 18 | |
| 19 | if os.file_ext(os.args[2]) != '.v' { |
| 20 | eprintln('Must be a V source file.') |
| 21 | exit(1) |
| 22 | } |
| 23 | |
| 24 | if !os.is_file(os.args[2]) { |
| 25 | eprintln('File not found.') |
| 26 | exit(1) |
| 27 | } |
| 28 | |
| 29 | to_send := os.args[2] |
| 30 | |
| 31 | content := os.read_file(to_send) or { |
| 32 | eprintln(err) |
| 33 | exit(1) |
| 34 | } |
| 35 | |
| 36 | share := http.post_form('https://play.vlang.io/share', { |
| 37 | 'code': content |
| 38 | })! |
| 39 | |
| 40 | response := json.decode(Response, share.body)! |
| 41 | url := 'https://play.vlang.io/p/${response.hash}' |
| 42 | |
| 43 | println(url) |
| 44 | if vshare.copy_to_clipboard(url) { |
| 45 | println('Copied URL to clipboard.') |
| 46 | } else { |
| 47 | println('Clipboard copy unavailable. Copy the URL manually.') |
| 48 | } |
| 49 | } |
| 50 | |