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
|
cd code-preloader
|
||||||
make prepare
|
make prepare
|
||||||
make build
|
make build
|
||||||
make install
|
sudo make install # either to install system-wide
|
||||||
|
make install PREFIX=$HOME/.local # or to install as a user
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
21
src/cli.cr
21
src/cli.cr
|
@ -69,25 +69,26 @@ module CodePreloader
|
||||||
""
|
""
|
||||||
].join("\n")
|
].join("\n")
|
||||||
|
|
||||||
# Writing the configuration content to the file
|
# Writing the configuration content to the file
|
||||||
File.write(config_file_path, config_content)
|
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
|
rescue e : Exception
|
||||||
STDERR.puts "An error occurred while creating the configuration file: #{e.message}"
|
abort("ERROR: Unable to create the configuration file: #{e.message}")
|
||||||
exit(1)
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def exec_version
|
def exec_version
|
||||||
abort("FIXME: Not implemented!")
|
puts "#{PROGRAM_NAME} v#{VERSION}"
|
||||||
|
exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec_none
|
def exec_none
|
||||||
abort("No command specified!")
|
STDERR.puts @config.parser
|
||||||
|
abort("ERROR: No command specified!")
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec_help
|
def exec_help
|
||||||
abort("FIXME: Not implemented!")
|
puts @config.parser
|
||||||
|
exit(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def exec_pack(pack_options)
|
def exec_pack(pack_options)
|
||||||
|
|
|
@ -41,7 +41,6 @@ module CodePreloader
|
||||||
@init_options = InitOptions.new
|
@init_options = InitOptions.new
|
||||||
|
|
||||||
parser.banner = [
|
parser.banner = [
|
||||||
"#{PROGRAM_NAME} v#{VERSION}",
|
|
||||||
"Usage: code-preloader init [options]\n",
|
"Usage: code-preloader init [options]\n",
|
||||||
"Global options:"
|
"Global options:"
|
||||||
].join("\n")
|
].join("\n")
|
||||||
|
@ -81,7 +80,6 @@ module CodePreloader
|
||||||
@pack_options = PackOptions.new
|
@pack_options = PackOptions.new
|
||||||
|
|
||||||
parser.banner = [
|
parser.banner = [
|
||||||
"#{PROGRAM_NAME} v#{VERSION}",
|
|
||||||
"Usage: code-preloader pack [options] DIR ...\n",
|
"Usage: code-preloader pack [options] DIR ...\n",
|
||||||
"Global options:"
|
"Global options:"
|
||||||
].join("\n")
|
].join("\n")
|
||||||
|
@ -151,19 +149,16 @@ module CodePreloader
|
||||||
def parse_arguments(args : Array(String))
|
def parse_arguments(args : Array(String))
|
||||||
@parser = OptionParser.new do |parser|
|
@parser = OptionParser.new do |parser|
|
||||||
parser.banner = [
|
parser.banner = [
|
||||||
"#{PROGRAM_NAME} v#{VERSION}",
|
|
||||||
"Usage: code-preloader <subcommand> [options] [DIR] [...]\n",
|
"Usage: code-preloader <subcommand> [options] [DIR] [...]\n",
|
||||||
"Global options:"
|
"Global options:"
|
||||||
].join("\n")
|
].join("\n")
|
||||||
|
|
||||||
parser.on("--version", "Show version") do
|
parser.on("--version", "Show version") do
|
||||||
STDOUT.puts "#{PROGRAM_NAME} #{VERSION}"
|
@subcommand = Subcommand::Version
|
||||||
exit(0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on("-h", "--help", "Show this help") do
|
parser.on("-h", "--help", "Show this help") do
|
||||||
STDERR.puts parser
|
@subcommand = Subcommand::Help
|
||||||
exit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.separator "\nSubcommands:"
|
parser.separator "\nSubcommands:"
|
||||||
|
|
Loading…
Reference in a new issue