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
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/lgtm_hd/cli.rb', line 16
def run
program :name, LgtmHD::Configuration::PROGRAM_NAME
program :version, LgtmHD::VERSION
program :description, LgtmHD::Configuration::DESCRIPTION
program :help_formatter, Commander::HelpFormatter::TerminalCompact
default_command :transform
global_option '-i', '--interactive', 'Turn on interactive Mode. In case you forgot all these super complexive args and options' do say "-- LGTM HD Interactive Mode --" end
global_option '-d', '--dest DIR', String, 'Directory to export the LGTM image to. Default value is user\'s current working directory'
global_option '-p', '--preview QUALITY', String, 'Quality of Image preview live on terminal at the end. Accepted values for QUALITY are [high, low, none]. Default value is high. Set to none for skipping'
command :random do |c|
c.syntax = CMD_RANDOM_SYNTAX
c.summary = 'Fetch random images from LGTM.in'
c.description = ''
c.example 'Example', 'lgtm_hd random'
c.action do |args, options|
if options.interactive options.dest ||= ask('Destination Directory (Enter to skip): ')
options.preview ||= ask('Image Preview Quality? [high|low|none] (Enter to skip)')
end
dest_dir = CLI.destination_dir(options.dest)
dest_file_prefix = CLI.destination_file_prefix
check_uris(dest_dir)
say_step "Fetching from lgtm.in"
dest_uri,image_markdown = LgtmDotIn.fetch_random_image(dest_dir,dest_file_prefix) do |url, markdown|
say_step "Loading image at #{url}"
end
say_ok "Exported image to #{dest_uri}"
show_preview dest_uri, options.preview
copy_file_to_clipboard(dest_uri)
say "\nOr you can copy the markdown format below provided by lgtm.in"
say_code_block "#{image_markdown}"
say "\nIf the image does not have LGTM texts on it, run the cmd below"
say_code_block "lgtm_hd #{dest_uri}"
end
end
command :transform do |c|
c.syntax = CMD_TRANSFORM_SYNTAX
c.summary = 'Generate LGTM text on top of image URL or local image File'
c.description = 'The command \e[3mtransform\e[0m is the default command hence you can skip typing it instead'
c.example 'Example', 'lgtm_hd http://domain.com/image.png'
c.action do |args, options|
if args.length >= 1
source_uri = args[0]
elsif options.interactive source_uri ||= ask('Source Image (URL or Path/to/file): ')
options.dest ||= ask('Destination Directory (Enter to skip): ')
options.preview ||= ask('Image Preview Quality [high|low|none] (Enter to skip): ')
else
help_the_noobie
end
source_uri = CLI.source_uri(source_uri)
dest_dir = CLI.destination_dir(options.dest)
check_uris(dest_dir, source_uri)
dest_file = File.join(dest_dir, CLI.destination_file_prefix + CLI.extname(source_uri))
say_step "Reading and inspecting source at #{source_uri}"
meme_generator = MemeGenerator.new(input_image_uri:source_uri, output_image_uri:dest_file)
say_step "Transforming Image"
meme_generator.draw
say_step "Exporting to file"
meme_generator.export do |output|
say_ok "Exported LGTM image to #{output}."
show_preview output, options.preview
copy_file_to_clipboard output
end end end
run!
end
|