Add expanded usage information to commands
This commit is contained in:
parent
47d600bb3b
commit
29f46629ed
2 changed files with 67 additions and 4 deletions
70
bin/ebooks
70
bin/ebooks
|
@ -8,7 +8,12 @@ module Ebooks
|
|||
APP_PATH = Dir.pwd # XXX do some recursive thing instead
|
||||
|
||||
def self.new(reponame)
|
||||
usage = "Usage: ebooks new <reponame>"
|
||||
usage = <<STR
|
||||
Usage: ebooks new <reponame>
|
||||
|
||||
Creates a new skeleton repository defining a template bot in
|
||||
the current working directory specified by <reponame>.
|
||||
STR
|
||||
|
||||
if reponame.nil?
|
||||
log usage
|
||||
|
@ -33,10 +38,21 @@ module Ebooks
|
|||
end
|
||||
|
||||
def self.consume(pathes)
|
||||
usage = <<STR
|
||||
Usage: ebooks consume <corpus_path> [corpus_path2] [...]
|
||||
|
||||
Processes some number of text files or json tweet corpuses
|
||||
into usable models. These will be output at model/<name>.model
|
||||
STR
|
||||
|
||||
if pathes.empty?
|
||||
log usage
|
||||
exit
|
||||
end
|
||||
|
||||
pathes.each do |path|
|
||||
filename = File.basename(path)
|
||||
shortname = filename.split('.')[0..-2].join('.')
|
||||
hash = Digest::MD5.hexdigest(File.read(path))
|
||||
|
||||
outpath = File.join(APP_PATH, 'model', "#{shortname}.model")
|
||||
Model.consume(path).save(outpath)
|
||||
|
@ -45,6 +61,17 @@ module Ebooks
|
|||
end
|
||||
|
||||
def self.gen(model_path, input)
|
||||
usage = <<STR
|
||||
Usage: ebooks gen <model_path> [input]
|
||||
|
||||
Make a test tweet from the processed model at <model_path>.
|
||||
Will respond to input if provided.
|
||||
STR
|
||||
if model_path.nil?
|
||||
log usage
|
||||
exit
|
||||
end
|
||||
|
||||
model = Model.load(model_path)
|
||||
if input && !input.empty?
|
||||
puts "@cmd " + model.make_response(input, 135)
|
||||
|
@ -54,11 +81,35 @@ module Ebooks
|
|||
end
|
||||
|
||||
def self.score(model_path, input)
|
||||
usage = <<STR
|
||||
Usage: ebooks score <model_path> <input>
|
||||
|
||||
Scores "interest" in some text input according to how
|
||||
well unique keywords match the model.
|
||||
STR
|
||||
if model_path.nil? || input.nil?
|
||||
log usage
|
||||
exit
|
||||
end
|
||||
|
||||
model = Model.load(model_path)
|
||||
model.score_interest(input)
|
||||
end
|
||||
|
||||
def self.archive(username, outpath)
|
||||
usage = <<STR
|
||||
Usage: ebooks archive <username> <outpath>
|
||||
|
||||
Downloads a json corpus of the <username>'s tweets to <outpath>.
|
||||
Due to API limitations, this can only receive up to ~3000 tweets
|
||||
into the past.
|
||||
STR
|
||||
|
||||
if username.nil? || outpath.nil?
|
||||
log usage
|
||||
exit
|
||||
end
|
||||
|
||||
Archive.new(username, outpath).sync
|
||||
end
|
||||
|
||||
|
@ -73,6 +124,17 @@ module Ebooks
|
|||
end
|
||||
|
||||
def self.jsonify(paths)
|
||||
usage = <<STR
|
||||
Usage: ebooks jsonify <old_corpus_path> [old_corpus_path2] [...]
|
||||
|
||||
Takes an old-style corpus of plain tweet text and converts it to json.
|
||||
STR
|
||||
|
||||
if paths.empty?
|
||||
log usage
|
||||
exit
|
||||
end
|
||||
|
||||
paths.each do |path|
|
||||
name = File.basename(path).split('.')[0]
|
||||
new_path = name + ".json"
|
||||
|
@ -102,12 +164,12 @@ module Ebooks
|
|||
def self.command(args)
|
||||
usage = """Usage:
|
||||
ebooks new <reponame>
|
||||
ebooks consume <corpus_path> [...]
|
||||
ebooks consume <corpus_path> [corpus_path2] [...]
|
||||
ebooks gen <model_path> [input]
|
||||
ebooks score <model_path> <input>
|
||||
ebooks archive <@user> <outpath>
|
||||
ebooks tweet <model_path> <@bot>
|
||||
ebooks jsonify <old_corpus_path> [...]
|
||||
ebooks jsonify <old_corpus_path> [old_corpus_path2] [...]
|
||||
"""
|
||||
|
||||
if args.length == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue