Class: Pindo::Command::Utils::Encrypt
- Inherits:
-
Pindo::Command::Utils
- Object
- CLAide::Command
- Pindo::Command
- Pindo::Command::Utils
- Pindo::Command::Utils::Encrypt
- Defined in:
- lib/pindo/command/utils/encrypt.rb
Constant Summary
Constants inherited from Pindo::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from Pindo::Command
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Encrypt
constructor
A new instance of Encrypt.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from Pindo::Command
command_name, #initialize_options, run, use_cache?
Methods included from Funlog::Mixin
Methods included from Pindoconfig::Mixin
Constructor Details
#initialize(argv) ⇒ Encrypt
Returns a new instance of Encrypt.
63 64 65 66 67 68 69 |
# File 'lib/pindo/command/utils/encrypt.rb', line 63 def initialize(argv) @input_path = argv.shift_argument @output_dir = argv.option('output') @password = argv.option('password') super(argv) @additional_args = argv.remainder! end |
Class Method Details
.options ⇒ Object
56 57 58 59 60 61 |
# File 'lib/pindo/command/utils/encrypt.rb', line 56 def self. [ ['--output=PATH', '指定加密文件输出目录(默认: ./encrypted)'], ['--password=PASSWORD', '加密密码(不推荐使用,建议交互式输入)'] ].concat(super) end |
Instance Method Details
#run ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pindo/command/utils/encrypt.rb', line 77 def run @input_path = File.(@input_path) # 获取加密密码 @password ||= prompt_password # 确定输出目录 @output_dir ||= File.join(Dir.pwd, 'encrypted') @output_dir = File.(@output_dir) FileUtils.mkdir_p(@output_dir) Funlog.instance.("开始加密...") Funlog.instance.("输出目录: #{@output_dir}") # 执行加密 if File.file?(@input_path) encrypt_single_file(@input_path) elsif File.directory?(@input_path) encrypt_directory(@input_path) end Funlog.instance.("加密完成!") Funlog.instance.("加密文件保存在: #{@output_dir}") end |
#validate! ⇒ Object
71 72 73 74 75 |
# File 'lib/pindo/command/utils/encrypt.rb', line 71 def validate! super help! '请指定要加密的文件或目录路径' unless @input_path help! "路径不存在: #{@input_path}" unless File.exist?(@input_path) end |