Class: XoltiCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/xolti.rb

Instance Method Summary collapse

Instance Method Details

#__print_licenseObject



112
113
114
115
116
117
118
119
# File 'lib/xolti.rb', line 112

def __print_license()
	puts "Xolti version #{XoltiVersion.get}, Copyright (C) 2016 Rémi Even"
	puts "Xolti comes with ABSOLUTELY NO WARRANTY."
	puts "This is free software, and you are welcome to redistribute it"
	puts "under the terms of the GPLv3."
	puts "The complete license can be found at \"https://www.gnu.org/licenses/gpl.txt\"."
	puts "The source code of xolti can be found at \"https://github.com/RemiEven/xolti\"."
end

#__print_versionObject



105
106
107
# File 'lib/xolti.rb', line 105

def __print_version()
	puts XoltiVersion.get
end

#add(file) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xolti.rb', line 38

def add(file)
	config = self.load_config {|e| puts e.message; exit 1 }
	if File.file?(file)
		PrintUtils.puts_single "Adding header to #{file}"
		Core.licensify(file, config) if !Core.has_header(file, config)
	else
		FileFinder.explore_folder(file)
			.reject{|source_file| Core.has_header(source_file, config)}
			.each do |source_file|
				PrintUtils.puts_single "Adding header to #{source_file}"
				Core.licensify(source_file, config)
			end
	end
end

#delete(file) ⇒ Object



83
84
85
86
87
# File 'lib/xolti.rb', line 83

def delete(file)
	PrintUtils.puts_single "Deleting header in #{file}"
	config = self.load_config {|e| puts e.message; exit 1 }
	Core.delete_header(file, config)
end

#generate_licenseObject



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/xolti.rb', line 90

def generate_license()
	config = self.load_config {|e| puts e.message; exit 1 }
	filename = "LICENSE"
	if File.exists?(File.join(Dir.pwd, filename)) then
		PrintUtils.puts_single "There is already a #{filename} file. Abort generation."
	else
		full_license = IO.binread(Resources.get_full_license_path(config.license))
		File.write(filename, full_license % config.project_info)
		PrintUtils.puts_single "Created the #{filename} file (#{config.license})"
	end
end

#initObject



167
168
169
170
171
172
173
174
175
176
# File 'lib/xolti.rb', line 167

def init()
	config = self.load_config
	return PrintUtils.puts_single "Xolti is already initialiazed" if config != nil
	PrintUtils.puts_single "Initializing xolti project"
	config = {"project_info" => {}}
	self.ask_for_name(config)
	self.ask_for_author(config)
	self.ask_for_license(config)
	File.write("xolti.yml", config.to_yaml)
end

#list_missingObject



72
73
74
75
76
77
78
79
80
# File 'lib/xolti.rb', line 72

def list_missing()
	dir = Dir.pwd
	config = self.load_config {|e| puts e.message; exit 1 }
	missing_headers = FileFinder.explore_folder(dir)
		.reject{|file| Core.has_header(file, config)}
	return PrintUtils.puts_single "All files OK" if missing_headers.empty?
	PrintUtils.puts_single "Files missing (proper) header:"
	PrintUtils.puts(missing_headers.map{|file| file.sub(dir + "/", "")}, 1)
end

#status(file = ".") ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xolti.rb', line 54

def status(file = ".")
	config = self.load_config {|e| puts e; exit 1 }
	if File.file?(file)
		PrintUtils.puts self.check_file(file, config) || "Correct header"
	else
		FileFinder.explore_folder(file)
			.each do |source_file|
				message = self.check_file(source_file, config)
				if (message)
					PrintUtils.puts_single "#{source_file}"
					PrintUtils.puts(message, 1)
					PrintUtils.puts_single ""
				end
			end
	end
end