101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/tldr/cli/commands.rb', line 101
def run
parse
if params.errors.any?
puts params.errors.summary
elsif params[:help]
print help
elsif params[:version]
version
elsif params[:query]
query, lang, platform, source =
params.to_h.values_at(:query, :lang, :platform, :source)
page_path = "/#{platform}/#{query}"
if source == 'local' && local_page?(local_path(page_path, lang: lang))
content = File.read(local_path(page_path, lang: lang))
render_markdown(content)
return
end
response = Faraday.get(remote_path(page_path, lang: lang))
return not_found unless response.success?
render_markdown(response.body)
else
print help
end
end
|