Skip to content

Commit

Permalink
Refactor config initializer and options parser
Browse files Browse the repository at this point in the history
This commit refactors the `ConfigInitializer` class and the `run_options_parser` method in the `options.cr` file.

In the `ConfigInitializer` class, the exception handling for creating the config file and reading the config file has been simplified. The previous code had unnecessary print statements and did not handle exceptions properly. Now, the code simply rescues any exception without printing any error messages.

In the `options.cr` file, the case statements for generating completion scripts have been modified. The previous code printed instructions on how to save the completion scripts, but those instructions have been removed. Additionally, the `banner` method in the `noir.cr` file has been removed as it was not being used.

These changes improve the readability and maintainability of the code.

Signed-off-by: HAHWUL <hahwul@gmail.com>
  • Loading branch information
hahwul committed Nov 1, 2024
1 parent 67ec0f2 commit 90a50ed
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/config_initializer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class ConfigInitializer

# Create the config file if it doesn't exist
File.write(@config_file, generate_config_file) unless File.exists?(@config_file)
rescue e : Exception
puts "Failed to create config directory or file: #{e.message}"
puts "Using default config."
rescue
end

def read_config
Expand Down Expand Up @@ -71,9 +69,6 @@ class ConfigInitializer
final_options = default_options.merge(symbolized_hash) { |_, _, new_val| new_val }
final_options
rescue e : Exception
puts "Failed to read config file: #{e.message}"
puts "Using default config."

default_options
end
end
Expand Down
4 changes: 1 addition & 3 deletions src/noir.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ module Noir
VERSION = "0.18.0"
end

# Print banner
banner()

# Run options parser
noir_options = run_options_parser()

Expand Down Expand Up @@ -57,6 +54,7 @@ if noir_options["exclude_codes"] != ""
end

# Run Noir
banner()
app = NoirRunner.new noir_options
start_time = Time.monotonic

Expand Down
4 changes: 1 addition & 3 deletions src/options.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ def run_options_parser
case var
when "zsh"
puts generate_zsh_completion_script
STDERR.puts "\n> Instructions: Copy the content above and save it in the zsh-completion directory as _noir".colorize(:yellow)
when "bash"
puts generate_bash_completion_script
STDERR.puts "\n> Instructions: Copy the content above and save it in the .bashrc file as noir.".colorize(:yellow)
when "fish"
puts generate_fish_completion_script
STDERR.puts "\n> Instructions: Copy the content above and save it in the fish-completion directory as noir.fish".colorize(:yellow)
else
puts "ERROR: Invalid completion type.".colorize(:yellow)
puts "e.g., noir --generate-completion zsh"
Expand All @@ -164,6 +161,7 @@ def run_options_parser
end
parser.separator "\n OTHERS:".colorize(:blue)
parser.on "-h", "--help", "Show help" do
banner()
puts parser
puts ""
puts "EXAMPLES:"
Expand Down

0 comments on commit 90a50ed

Please sign in to comment.