Module: Drakkon::Version

Defined in:
lib/drakkon/lib/version.rb

Overview

Run Command for CLI

Class Method Summary collapse

Class Method Details

.args(raw = nil) ⇒ Object



4
5
6
7
8
# File 'lib/drakkon/lib/version.rb', line 4

def self.args(raw = nil)
  @args ||= raw

  @args
end

.install!(raw) ⇒ Object

General Run



22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
78
79
80
81
# File 'lib/drakkon/lib/version.rb', line 22

def self.install!(raw)
  # Safety if nothing provided
  if raw.nil? || raw.empty?
    LogBot.fatal('Version', 'No Zip Provided!')
    file = prompt.ask('Full path to DragonRuby Zip?')
    unless File.exist?(file)
      LogBot.fatal('Version', 'Not able to find zip!')
      exit(1)
    end
    raw = [file]
  end

  zip = raw.first
  if zip.nil? || File.extname(zip) != '.zip'
    LogBot.fatal('Version', "Invalid Argument! Must be a zip file! '#{zip}'")
    exit(1)
  end

  Dir.mktmpdir('drakkon-sauce-') do |tmp|
    # full_path = "#{Dir.pwd}/#{zip}"

    # Execut Unzip / Better Way to do this?
    system("unzip -q -d #{tmp} #{zip}")

    # Find Dir
    dr_dir = Dir["#{tmp}/*"].first
    unless dr_dir.include?('dragonruby-')
      LogBot.fatal('Version', "Valid Zip? Not finding DragonRuby Directory, #{dr_dir}")
      exit(2)
    end

    # Find Version
    unless File.exist?("#{dr_dir}/CHANGELOG-CURR.txt")
      LogBot.fatal('Version', "Version File Missing! #{"#{dr_dir}/CHANGELOG-CURR.txt"}")
      exit(2)
    end

    # Collect Version
    dr_version = File.open("#{dr_dir}/CHANGELOG-CURR.txt", &:readline)&.chomp&.split(' ', 2)&.last
    if dr_version.nil?
      LogBot.fatal('Version', "Unable to find DragonRuby Version!, #{dr_version}")
      exit(2)
    end

    # TODO: add overwrite
    if Hub.version?(dr_version)
      LogBot.fatal('Version', "Version already exists!, #{dr_version}")
      exit(3)
    end

    # Copy
    FileUtils.cp_r(dr_dir, "#{Hub.dir}/#{dr_version}/")

    # Save
    Hub.version_add(dr_version)

    # Finish
    LogBot.info('Version', "#{dr_version} Installed!")
  end
end

.listObject



10
11
12
# File 'lib/drakkon/lib/version.rb', line 10

def self.list
  LogBot.info('Versions', Hub.versions.join(', '))
end

.promptObject



83
84
85
# File 'lib/drakkon/lib/version.rb', line 83

def self.prompt
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
end

.setObject



14
15
16
17
18
19
# File 'lib/drakkon/lib/version.rb', line 14

def self.set
  current = "(Current: #{Settings.version.pastel(:bright_blue)})"
  version = prompt.select("Select version #{current}", Hub.versions_sorted, filter: true)

  Settings.update(:version, version)
end