module Pod class Command class JxedtCommand < Command class User < JxedtCommand self.summary = '用户操作,添加和删除用户目录,用来统一路径,方便做源码和二进制的link.' self.description = <<-DESC 用户操作,添加和删除用户目录,用来统一路径,方便做源码和二进制的link. DESC self.command = 'user' self.arguments = [ ] def self.options [ ['--add', '添加用户目录,/Users/cocoapods-jxedt'], ['--delete', '删除用户目录,/Users/cocoapods-jxedt'] ] end def initialize(argv) @add = argv.flag?('add', false) @delete = argv.flag?('delete', false) @name = 'cocoapods-jxedt' super end def validate! help! '请指定要操作的命令, add or delete' unless @add || @delete help! '输入的目录不正确!' if @name.length == 0 super end def run if @add make_dir else delete_dir end end def make_dir dirname = "/Users/#{@name}" help! "目录已存在!" if File.exist?(dirname) `sudo mkdir #{dirname} && sudo chmod -R 777 #{dirname}` end def delete_dir help! '因删除操作存在风险,暂不支持删除,请自行删除!' if @name != 'cocoapods-jxedt' dirname = "/Users/#{@name}" help! "目录不存在!" unless File.exist?(dirname) `sudo rm -rf #{dirname}` end end end end end