lib/site_hook/cli.rb in site_hook-0.8.2 vs lib/site_hook/cli.rb in site_hook-0.9.3
- old
+ new
@@ -1,48 +1,31 @@
-require 'gli'
+require 'thor'
require 'highline'
require 'paint'
require 'pathname'
+require 'site_hook/paths'
require 'site_hook/exceptions'
require 'site_hook/deprecate'
+commands = SiteHook::Paths.lib_dir.join('site_hook/commands').children
+commands.each do |filename|
+ next if filename == '.' or filename == '..'
+ f = filename.dirname
+ require "#{f + filename.basename('.*')}"
+end
+
module SiteHook
- class App
- extend GLI::App
- version SiteHook::VERSION
- # don't use config_file just use ~/.shrc/config's cli:...
- # projects are in .shrc/config
- commands_from 'site_hook/commands'
- desc 'Print info on the gem.'
- command 'gem-info' do |c|
- c.action do |global_options, options, arguments|
- @hl.say "Gem Name: #{SiteHook::Gem::Info.name}"
- @hl.say "Gem Constant: #{SiteHook::Gem::Info.constant_name}"
- @hl.say "Gem Author: #{SiteHook::Gem::Info.author}"
- @hl.say "Gem Version: v#{SiteHook::VERSION}"
- end
+ class CLI < Thor
+ desc '--version, -v', 'returns version and exits'
+ def __version
+ puts SiteHook::VERSION
end
- around do |global_options, command, options, args, code|
- @config_hash = YAML.load_file(SiteHook::Paths.config) || YAML.load_file(SiteHook::Paths.old_config)
- @hl = HighLine.new(STDIN, STDOUT, 80, 1, 2, 0)
- code.call
- end
- pre do |global_options, command, options, args|
- if SiteHook::Paths.old_config.exist?
- continue = SiteHook::Deprecation.deprecate(
- "#{SiteHook::Paths.old_config.to_s} is deprecated in favor of #{SiteHook::Paths.config}",
- <<~INSTRUCT,
- Please run `#{exe_name} config upgrade-shrc` to rectify this.
- Once version 1.0.0 is released, #{SiteHook::Paths.config} will
- be the only config file option, and #{SiteHook::Paths.old_config} will not be allowed.
- any existance of ~/.jph after the 1.0.0 release will result in an Exception being raised.
- Once the exception is raised, site_hook will exit and return a 99 status code.
- INSTRUCT
- true
+ map ['-v', '--version'] => :__version
- )
- continue
- else
- # don't do anything
- end
- end
+ desc 'config [subcommand] [options]', 'configure site_hook'
+ subcommand('config', SiteHook::Commands::ConfigClass)
+ desc 'server [subcommand] [options]', 'run server actions'
+ subcommand('server', SiteHook::Commands::ServerClass)
+ desc 'jekyll [subcommand] [options]', 'run jekyll actions'
+ subcommand('jekyll', SiteHook::Commands::JekyllClass)
+
end
-end
+end
\ No newline at end of file