lib/plagiarism/cli.rb in plagiarism2-0.0.5 vs lib/plagiarism/cli.rb in plagiarism2-0.0.6
- old
+ new
@@ -4,15 +4,26 @@
module Plagiarism
class Cli < Thor
include Thor::Actions
CONFIG_PATH = '~/.plagiarism.yml'
+ class << self
+ def load_config(path)
+ config = YAML.load_file(File.expand_path path)
+ Config.strategies = config['strategies'].split(',').map &:strip
+ Config.whitelists = config['whitelists'].split(',').map &:strip
+ Config.bing_key = config['bing_key']
+ Config.google_key = config['google_key']
+ Config.google_cx = config['google_cx']
+ end
+ end
+
desc 'init', 'Create file for plagiarism to load config'
method_option :path, aliases: '-p', desc: 'where put the config', type: :string, default: CONFIG_PATH
def init
create_file options[:path], <<-STRING
-strategies: "duck, yahoo"
+strategies: "yahoo"
whitelists: "www.ring.md, blog.ring.md"
bing_key: xxx
google_key: xxx
google_cx: xxx
STRING
@@ -20,16 +31,18 @@
desc 'unique', 'Check the unique content from search engines'
method_option :content, aliases: '-c', desc: 'content which need to checked', type: :string, required: true
method_option :path, aliases: '-p', desc: 'where put the config', type: :string, default: CONFIG_PATH
def unique
- config = YAML.load_file(File.expand_path options[:path])
- Config.strategies = config['strategies'].split(',').map &:strip
- Config.whitelists = config['whitelists'].split(',').map &:strip
- Config.bing_key = config['bing_key']
- Config.google_key = config['google_key']
- Config.google_cx = config['google_cx']
-
+ Cli.load_config(options[:path])
puts Plagiarism.unique? options[:content]
+ end
+
+ desc 'match', 'Get the first match from search engines'
+ method_option :content, aliases: '-c', desc: 'content which need to get', type: :string, required: true
+ method_option :path, aliases: '-p', desc: 'where put the config', type: :string, default: CONFIG_PATH
+ def match
+ Cli.load_config(options[:path])
+ puts Plagiarism.match options[:content]
end
end
end