Class: Uniword::ProtectCLI

Inherits:
Thor
  • Object
show all
Includes:
CLIHelpers
Defined in:
lib/uniword/cli/protect_cli.rb

Overview

Protect subcommand for Uniword CLI.

Manages document editing restrictions and password protection.

Instance Method Summary collapse

Methods included from CLIHelpers

included

Instance Method Details

#apply(path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/uniword/cli/protect_cli.rb', line 31

def apply(path)
  doc = load_document(path)
  manager = Protect::Manager.new(doc)

  protection_type = options[:type].to_sym
  manager.apply(protection_type, password: options[:password])

  doc.save(options[:output])
  say "Applied #{options[:type]} protection to #{options[:output]}",
      :green
  say "Password protected" if options[:password]
rescue ArgumentError => e
  say "Error: #{e.message}", :red
  exit 1
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end

#info(path) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/uniword/cli/protect_cli.rb', line 79

def info(path)
  doc = load_document(path)
  manager = Protect::Manager.new(doc)

  if manager.protected?
    details = manager.info
    say "Document is protected:", :yellow
    say "  Type: #{details[:type]}"
    say "  Password: #{details[:password_protected] ? 'Yes' : 'No'}"
  else
    say "Document is not protected.", :green
  end
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end

#remove(path) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/uniword/cli/protect_cli.rb', line 59

def remove(path)
  doc = load_document(path)
  manager = Protect::Manager.new(doc)

  manager.remove
  doc.save(options[:output])
  say "Removed protection from #{options[:output]}", :green
rescue Uniword::Error => e
  handle_error(e)
rescue StandardError => e
  handle_error(e)
end