Skip to content

Commit

Permalink
Change the command line interface to name exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 29, 2023
1 parent e5e8cbb commit fd7cdb1
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions lib/slideck/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ class CLI
desc "Watch for changes in the file with slides"
end

# The error exit code
#
# @return [Integer]
#
# @api private
CODE_ERROR = 1
private_constant :CODE_ERROR

# The success exit code
#
# @return [Integer]
#
# @api private
CODE_SUCCESS = 0
private_constant :CODE_SUCCESS

# The pattern to detect color option
#
# @return [Regexp]
Expand Down Expand Up @@ -140,7 +156,7 @@ def print_version
return unless params[:version]

@output.puts VERSION
exit
exit_success
end

# Print help
Expand All @@ -154,7 +170,7 @@ def print_help
return unless params[:help] || file_missing?

@output.print help
exit
exit_success
end

# Check whether a file is missing
Expand All @@ -177,7 +193,7 @@ def print_errors
return unless params.errors.any?

@error_output.puts params.errors.summary
exit 1
exit_error
end

# Rescue errors
Expand All @@ -195,7 +211,7 @@ def rescue_errors
raise err if params[:debug]

@error_output.puts "Error: #{err}"
exit 1
exit_error
end

# Check whether no color environment variable is present
Expand Down Expand Up @@ -226,5 +242,27 @@ def no_color_env?(cmd_args, env)
def color(no_color_env)
params[:no_color] || no_color_env ? :never : params[:color]
end

# Exit with the error code
#
# @raise [SystemExit]
#
# @return [void]
#
# @api private
def exit_error
exit CODE_ERROR
end

# Exit with the success code
#
# @raise [SystemExit]
#
# @return [void]
#
# @api private
def exit_success
exit CODE_SUCCESS
end
end # CLI
end # Slideck

0 comments on commit fd7cdb1

Please sign in to comment.