lib/lhj/command/yapi.rb in lhj-tools-0.1.71 vs lib/lhj/command/yapi.rb in lhj-tools-0.1.72
- old
+ new
@@ -9,16 +9,17 @@
module Lhj
class Command
# generate model from yapi
class Yapi < Command
self.summary = '通过yapi接口生成请求'
- self.description = '更新 ~/.lhj/yapi.yml 文件配置后执行`lhj api`生成接口模型'
+ self.description = '执行`lhj api`生成接口模型'
def self.options
[
%w[--id api的id],
%w[--model-pre 模型的前缀],
+ %w[--model-name 模型的名称],
%w[--save 保存生成文件]
]
end
def initialize(argv)
@@ -63,10 +64,11 @@
print_req_query(res_body['data'])
# 4.print request method
service_code = print_http_method(res_body['data'], result_model_name, param_model_name)
# 5.save to file
file_map = save_to_file(service_code) if @save
+ puts file_map
# 6.push to git
push_to_git if @sync
# 7.notify robot
notify_robot(file_map) if @notify
end
@@ -96,16 +98,17 @@
@sub_folder_name ||= time.strftime('%Y%m%d%H%M%S')
@sub_folder_name
end
def save_to_file(service_code)
+ name = model_name
file_name = gen_model_name('')
unless File.exist?(File.expand_path(sub_folder_name, '.'))
FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.'))
end
h_file = File.join('.', sub_folder_name, "#{file_name}.h")
m_file = File.join('.', sub_folder_name, "#{file_name}.m")
- service_file = File.join('.', sub_folder_name, "#{model_pre}#{model_name}Service.m")
+ service_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Service.m")
File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive?
File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
File.write(service_file, service_code) if service_code
puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green
{ h_file: h_file, m_file: m_file, s_file: service_file, api_id: api_id }