lib/mt_tool/commands.rb in mt_tool-0.1.5 vs lib/mt_tool/commands.rb in mt_tool-1.0.0
- old
+ new
@@ -1,50 +1,57 @@
-
require 'thor'
require 'mt_tool/module/module'
-require 'mt_tool/oc_model/oc_model'
+require 'logger'
module MtTool
class CLI < Thor
include Thor::Actions
-
- desc 'generate <Path> <Module Name> <Language> <Prefix - 前缀> <Author - 作者>', '直接生成项目 例子: yk_command generate . HomeModule oc MT Tom.Liu '
- method_option :generate, aliases: '-g'
-
- def generate(path = nil, name, lang, class_prefix, author)
- Module.new(self .args,self .options).generate(path, name, lang, class_prefix, author)
+ def initialize(*args)
+ super
+ @logger = Logger.new(STDOUT)
+ @logger.level = Logger::DEBUG
+ @logger.formatter = proc do |severity, datetime, progname, msg|
+ "[#{severity}][#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
+ end
end
- desc 'create <Path>', '在某个路径下交互式生成项目'
- method_option :create, aliases: '-c'
-
- def create(path = nil)
- Module.new(self .args,self .options ).create(path)
-
+ def self.exit_on_failure?
+ true
end
+ desc 'vmod', '生成viper模块文件'
+ method_option :name, aliases: '-n', desc: 'Module name', required: true
+ method_option :author, aliases: '-a', desc: 'Author name', required: true
+ method_option :path, aliases: '-p', desc: 'Target path', required: true
+ def vmod
+ name = options[:name]
+ author = options[:author]
+ path = options[:path]
- desc 'vmod <module name > <author> <path> ', '生成viper模块文件'
- method_option :vmod, aliases: '-v'
- def generateViperModule(name,author, path )
- Module.new(self .args,self .options).create_viper_module(path, name, "swift","", author)
- end
+ @logger.debug "====== VIPER Module Generation Started ======"
+ @logger.debug "Command Parameters:"
+ @logger.debug " - Module name: #{name}"
+ @logger.debug " - Author: #{author}"
+ @logger.debug " - Path: #{path}"
+ @logger.debug "Thor Options: #{options.inspect}"
+ @logger.debug "Thor Arguments: #{args.inspect}"
- desc 'model_class <prefix> <class name > <json file path> <output path>', '根据json文件生成模型类'
- method_option :create, aliases: '-c'
- def model_class(prefix,name, path ,output_path)
- OcModel.new(self .args,self .options ).create(prefix,name ,path,output_path)
-
+ begin
+ @logger.debug "Creating new Module instance..."
+ module_instance = Module.new(self.args, self.options)
+
+ @logger.debug "Calling create_viper_module..."
+ module_instance.create_viper_module(path, name, "swift", "", author)
+
+ @logger.info "Successfully generated VIPER module: #{name}"
+ @logger.debug "====== VIPER Module Generation Completed ======"
+ rescue => e
+ @logger.error "Failed to generate VIPER module: #{e.message}"
+ @logger.debug "Error backtrace:"
+ @logger.debug e.backtrace.join("\n")
+ @logger.debug "====== VIPER Module Generation Failed ======"
+ raise e
+ end
end
-
- desc 'qt_model_class <prefix> <class name > <json file path> <output path>', '使用quicktype根据json文件生成模型类'
- method_option :create, aliases: '-c'
- def qt_model_class(prefix,name, path ,output_path)
- OcModel.new(self .args,self .options ).qt_create(prefix,name ,path,output_path)
-
- end
-
-
-
end
end