From d2d311a866fff30d735cedac70e73ebb3c019583 Mon Sep 17 00:00:00 2001 From: Glenn Date: Thu, 4 Jan 2024 13:05:41 +0100 Subject: [PATCH] refactor: unify management of subcommands --- README.md | 3 ++- src/cli.cr | 21 +++++++++++---------- src/config.cr | 9 ++------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ff5eb3e..4cdd937 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ git clone https://code.apps.glenux.net/glenux/code-preloader cd code-preloader make prepare make build -make install +sudo make install # either to install system-wide +make install PREFIX=$HOME/.local # or to install as a user ``` ## Usage diff --git a/src/cli.cr b/src/cli.cr index f73e08a..d73eaef 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -69,25 +69,26 @@ module CodePreloader "" ].join("\n") - # Writing the configuration content to the file - File.write(config_file_path, config_content) - STDERR.puts "Example configuration file created at: #{config_file_path}" + # Writing the configuration content to the file + File.write(config_file_path, config_content) + puts "Configuration file created at: #{config_file_path}" rescue e : Exception - STDERR.puts "An error occurred while creating the configuration file: #{e.message}" - exit(1) - - end + abort("ERROR: Unable to create the configuration file: #{e.message}") + end def exec_version - abort("FIXME: Not implemented!") + puts "#{PROGRAM_NAME} v#{VERSION}" + exit(0) end def exec_none - abort("No command specified!") + STDERR.puts @config.parser + abort("ERROR: No command specified!") end def exec_help - abort("FIXME: Not implemented!") + puts @config.parser + exit(0) end def exec_pack(pack_options) diff --git a/src/config.cr b/src/config.cr index 427a194..d979807 100644 --- a/src/config.cr +++ b/src/config.cr @@ -41,7 +41,6 @@ module CodePreloader @init_options = InitOptions.new parser.banner = [ - "#{PROGRAM_NAME} v#{VERSION}", "Usage: code-preloader init [options]\n", "Global options:" ].join("\n") @@ -81,7 +80,6 @@ module CodePreloader @pack_options = PackOptions.new parser.banner = [ - "#{PROGRAM_NAME} v#{VERSION}", "Usage: code-preloader pack [options] DIR ...\n", "Global options:" ].join("\n") @@ -151,19 +149,16 @@ module CodePreloader def parse_arguments(args : Array(String)) @parser = OptionParser.new do |parser| parser.banner = [ - "#{PROGRAM_NAME} v#{VERSION}", "Usage: code-preloader [options] [DIR] [...]\n", "Global options:" ].join("\n") parser.on("--version", "Show version") do - STDOUT.puts "#{PROGRAM_NAME} #{VERSION}" - exit(0) + @subcommand = Subcommand::Version end parser.on("-h", "--help", "Show this help") do - STDERR.puts parser - exit + @subcommand = Subcommand::Help end parser.separator "\nSubcommands:"