refactor: unify management of subcommands
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
f533680f9f
commit
d2d311a866
3 changed files with 15 additions and 18 deletions
|
@ -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
|
||||
|
|
15
src/cli.cr
15
src/cli.cr
|
@ -71,23 +71,24 @@ module CodePreloader
|
|||
|
||||
# Writing the configuration content to the file
|
||||
File.write(config_file_path, config_content)
|
||||
STDERR.puts "Example configuration file created at: #{config_file_path}"
|
||||
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)
|
||||
|
||||
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)
|
||||
|
|
|
@ -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 <subcommand> [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:"
|
||||
|
|
Loading…
Reference in a new issue