/
pastebin
executable file
·93 lines (77 loc) · 2.23 KB
/
pastebin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env ruby
# pastebin is a command line interface to pastebin.com
# It can read from a file or from STDIN
#
# Copyright (C) 2010 Doug Prostko
#
require 'optparse'
require 'pastebin'
# set up all the options stuff
options = {}
opts = OptionParser.new do |opts|
opts.banner = "pastebin is a CLI to http://pastebin.com
Usage: pastebin [options]
Examples: pastebin -f foo.rb -t ruby -e '10 Minutes'
cat foo.pl | pastebin -f - -t perl"
opts.separator ""
opts.separator "Options:"
opts.on("-f <file>", "--file <file>", String,
"Use a file for input, use \"-\" for STDIN") do |f|
options["api_paste_code"] = f
end
opts.on("-n", "--name <name>", String,
"Assign a name/title to your paste") do |n|
options["api_paste_name"] = n
end
opts.on("-s", "--subdomain <subdomain>", String,
"Paste to a specific subdomain") do |s|
options["api_paste_subdomain"] = s
end
opts.on("-r", "--raw <link>", String,
"Return raw text from a paste link") do |r|
options["raw"] = r
end
expire_array = [
"Never",
"10 Minutes",
"1 Hour",
"1 Day",
"1 Month",
]
expire_list = expire_array.join(", ")
opts.on("-e", "--expire <time>", expire_array, "These can be abbriviated, as long as they are unambigous. Defaults to '1 Month'", "#{expire_list}" ) do |e|
options["api_paste_expire_date"] = e
end
syntax_array = [ 'perl',
'python',
'c',
'ruby',
'bash',
'cpp',
'groovy',
'latex',
'java',
'php',
'sql',
'xml'
]
code_list = syntax_array.join(", ")
opts.on("-l", "--language <syntax>", syntax_array, "Syntax types can be abbriviated, as long as they are unambigous. There are many more supported languages than what is listed here. Defaults to 'text'", " #{code_list}") do |encoding|
options["api_paste_format"] = encoding
end
opts.on("-p", "--private", "Make paste private.") do
options["api_paste_private"] = "1"
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end
# parse options
opts.parse(ARGV)
pbin = Pastebin.new(options)
if options["raw"]
puts pbin.get_raw(options["raw"])
else
puts pbin.paste
end