Class: Zwischen::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/zwischen/setup.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSetup

Returns a new instance of Setup.



19
20
21
# File 'lib/zwischen/setup.rb', line 19

def initialize
  @shell = Thor::Shell::Color.new
end

Class Method Details

.runObject



11
12
13
# File 'lib/zwischen/setup.rb', line 11

def self.run
  new.run
end

.uninstallObject



15
16
17
# File 'lib/zwischen/setup.rb', line 15

def self.uninstall
  new.uninstall
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/zwischen/setup.rb', line 23

def run
  @shell.say("\nšŸ›”ļø  Installing Zwischen security layer...\n", :bold)

  check_tools
  configure_credentials
  install_hook
  create_config

  @shell.say("  āœ“ Done!", :green)
  @shell.say("\nZwischen will now scan automatically before pushes.")
  @shell.say("Run 'zwischen scan' to test it now.\n")
end

#uninstallObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zwischen/setup.rb', line 36

def uninstall
  @shell.say("\nšŸ—‘ļø  Zwischen Uninstall\n", :bold)

  project_root = Dir.pwd
  hook_path = Hooks.hook_path(project_root)

  # Remove hook
  if Hooks.installed?(project_root)
    if @shell.yes?("Remove git hook?", default: true)
      if Hooks.uninstall(project_root)
        @shell.say("  āœ“ Removed .git/hooks/pre-push", :green)
      else
        @shell.say("  āœ— Failed to remove hook", :red)
      end
    end
  else
    @shell.say("  ↳ No Zwischen hook found", :yellow)
  end

  # Remove config
  config_path = File.join(project_root, Config::CONFIG_FILE)
  if File.exist?(config_path)
    if @shell.yes?("Remove project config (.zwischen.yml)?", default: false)
      File.delete(config_path)
      @shell.say("  āœ“ Removed .zwischen.yml", :green)
    else
      @shell.say("  ↳ Kept .zwischen.yml", :yellow)
    end
  end

  # Remove credentials
  if File.exist?(Credentials.credentials_path)
    if @shell.yes?("Remove global credentials (~/.zwischen/credentials)?", default: false)
      File.delete(Credentials.credentials_path)
      @shell.say("  āœ“ Removed credentials", :green)
    else
      @shell.say("  ↳ Kept credentials", :yellow)
    end
  end

  @shell.say("\nāœ… Zwischen uninstalled from this project.\n", :green)
end