diff --git a/shard.yml b/shard.yml index f228d53..eb57dee 100644 --- a/shard.yml +++ b/shard.yml @@ -8,8 +8,8 @@ targets: wfetch: main: src/wfetch.cr - wf-tool: - main: src/wf-tool.cr + wfp-tool: + main: src/wfp-tool.cr crystal: '>= 1.19.1' diff --git a/src/wf-tool.cr b/src/wf-tool.cr deleted file mode 100644 index 1a68e66..0000000 --- a/src/wf-tool.cr +++ /dev/null @@ -1,94 +0,0 @@ -require "option_parser" - -orange = "\e[38;5;214m" -red = "\e[0;31m" -bold = "\033[1m" -reset = "\e[0m" - -sudo_user = ENV["SUDO_USER"]? -home = "/home/#{sudo_user}" - -OptionParser.parse do |parser| - parser.banner = "Usage: wf-tool [arguments]" - parser.on("-i", "--install-only", "Only instals wfetch; Does not run setup") { - if LibC.getuid != 0 - puts "#{red}#{bold}You must be in root to install wfetch!#{reset}" - exit(0) - end - - puts "#{orange}#{bold}wfetch installer#{reset}" - - File.copy("data/wfetch", "/usr/bin/wfetch") - - puts "#{orange}#{bold}Finished installing!#{reset}" - exit - } - parser.on("-u", "--uninstall", "Uninstalls wfetch"){ - if LibC.getuid != 0 - puts "#{red}#{bold}You must be in root to uninstall wfetch!#{reset}" - exit(0) - end - - File.delete("/usr/bin/wfetch") - File.delete("#{home}/.local/share/Wfetch/disp.toml") - File.delete("#{home}/.local/share/Wfetch/config.toml") - Dir.delete("#{home}/.local/share/Wfetch") - puts "#{bold}#{orange}Finished#{reset}" - exit - } - parser.on("-s", "--setup", "Runs setup") { - if LibC.getuid == 0 - puts "#{red}#{bold}Don't run the setup in root!#{reset}" - exit(0) - end - - Dir.mkdir(Path["~/.local/share/Wfetch"].expand(home: true)) - - - puts "Please enter your WeatherApi key (Learn to get one at README.md):" - - api = gets - - puts "Please enter the (closest) city you live in: " - - city = gets - - puts "#{orange}#{bold}Config setup finished. Starting disp setup.#{reset}" - - File.write(Path["~/.local/share/Wfetch/config.toml"].expand(home: true), " - api = \"#{api}\" - city = \"#{city}\" - ") - - puts "#{orange}#{bold}Would you like customary (1), metric (2), or both (3)?#{reset}" - - choice = gets - - if choice == "1" - File.copy("data/1.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true)) - elsif choice == "2" - File.copy("data/2.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true)) - elsif choice == "3" - File.copy("data/3.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true)) - else - File.copy("data/1.toml", Path["~/.local/share/Wfetch/disp.toml"].expand(home: true)) - end - - puts "#{orange}#{bold}Setup finnished. Enjoy!#{reset}" - exit - } - parser.on("-h", "--help", "Show this help") do - - puts parser - exit(1) - end - parser.invalid_option do |flag| - STDERR.puts "ERROR: #{flag} is not a valid option." - STDERR.puts parser - exit(1) - end - end - - if ARGV.empty? - puts "Run wf-tool -h" - end \ No newline at end of file diff --git a/src/wfp-tool.cr b/src/wfp-tool.cr new file mode 100644 index 0000000..7ed0365 --- /dev/null +++ b/src/wfp-tool.cr @@ -0,0 +1,40 @@ +orange = "\e[38;5;214m" +red = "\e[0;31m" +bold = "\033[1m" +reset = "\e[0m" + +Dir.mkdir("config") + + +puts "Please enter your WeatherApi key (Learn to get one at README.md):" + +api = gets + +puts "Please enter the (closest) city you live in: " + +city = gets + +puts "#{orange}#{bold}Config setup finished. Starting disp setup.#{reset}" + +File.write("config/config.toml", " + api = \"#{api}\" + city = \"#{city}\" +") + +puts "#{orange}#{bold}Would you like customary (1), metric (2), or both (3)?#{reset}" + +choice = gets + +if choice == "1" + File.copy("data/1.toml", "config/disp.toml") +elsif choice == "2" + File.copy("data/2.toml", "config/disp.toml") +elsif choice == "3" + File.copy("data/3.toml", "config/disp.toml") +else + File.copy("data/1.toml", "config/disp.toml") +end + +puts "#{orange}#{bold}Setup finnished. Enjoy!#{reset}" + +Dir.remove("data") \ No newline at end of file