Skip to content

Conversation

@omarkurt
Copy link
Member

@omarkurt omarkurt commented Apr 25, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a colorful ASCII art banner and tagline displayed when launching the tool, enhancing the visual experience in the terminal.
    • Added a "double" flag to the encode and decode commands for performing double URL encoding and decoding.
    • Added a Makefile to automate building and cleaning the application binary.
  • Chores

    • Updated dependencies to support new banner functionality and maintain compatibility.
    • Enhanced the README with new visual elements and a requirements section.
    • Removed the previous installation script in favor of streamlined build and install processes.

@coderabbitai
Copy link

coderabbitai bot commented Apr 25, 2025

Walkthrough

The changes update the Go module dependencies in go.mod by consolidating direct dependencies into a single require block and adding both new direct and indirect dependencies, notably introducing github.com/fatih/color. In the CLI root command implementation, import statements are reorganized, and a new function GetBanner() is introduced to print a colored ASCII art banner using the color package. The banner is now displayed as part of the CLI tool's long description when the root command is invoked. Additionally, the encode and decode CLI commands are enhanced with a new boolean double flag that enables double URL encoding and decoding, respectively, with updated function signatures and error handling to support this feature. A new Makefile is added to automate building and cleaning the binary. The install.sh script is removed. The README is enhanced with images and a requirements section.

Changes

File(s) Change Summary
go.mod Consolidated direct dependencies into one require block; added github.com/fatih/color and several indirect dependencies.
internal/cli/root.go Reorganized imports; added fmt and github.com/fatih/color; introduced GetBanner() to print a colored banner; updated rootCmd to display the banner in its long description.
internal/cli/encode.go Added boolean double flag for double URL encoding; updated encodeURL function signature and logic to support double encoding; updated command run logic to handle the flag.
internal/cli/decode.go Added boolean double flag for double URL decoding; updated decodeURL function signature and logic to support double decoding with error handling; updated command run logic to handle the flag.
Makefile Added new Makefile with targets for building and cleaning the funURL binary, including OS detection and colored banner printing.
README.md Added badge and images; introduced a "Requirements" section specifying Golang 1.18+; replaced closing text with an image.
install.sh Deleted the Bash install script that handled building and installation with user prompts and environment checks.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI (rootCmd)
    participant GetBanner
    participant color

    User->>CLI (rootCmd): Run CLI command
    CLI (rootCmd)->>GetBanner: Call GetBanner()
    GetBanner->>color: Print colored ASCII banner
    GetBanner-->>CLI (rootCmd): Return (prints banner as side effect)
    CLI (rootCmd)->>User: Display banner and long description
Loading
sequenceDiagram
    participant User
    participant CLI (encodeCmd)
    participant encodeURL

    User->>CLI (encodeCmd): Run encode with input and flags (component, double)
    CLI (encodeCmd)->>encodeURL: Call encodeURL(input, component, double)
    encodeURL-->>CLI (encodeCmd): Return encoded output
    CLI (encodeCmd)->>User: Display encoded output
Loading
sequenceDiagram
    participant User
    participant CLI (decodeCmd)
    participant decodeURL

    User->>CLI (decodeCmd): Run decode with input and flags (component, double)
    CLI (decodeCmd)->>decodeURL: Call decodeURL(input, component, double)
    decodeURL-->>CLI (decodeCmd): Return decoded output or error
    CLI (decodeCmd)->>User: Display decoded output or error message
Loading

Poem

In the terminal’s glow, a banner appears,
With colors so bright, it draws rabbit cheers!
New code hops in with a vibrant display,
Dependencies gathered, all tidy, hooray!
Double encode, double decode, a twist in the race,
Now URLs dance with a double embrace.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/cli/root.go (1)

14-15: Consider the impact of banner placement in Long description.

Using GetBanner() here works but has side effects - the banner will be printed to stdout whenever the Long description is accessed, not just when displaying help.

Consider moving the banner display to a more controlled location, such as the Execute() function or a pre-run hook:

var rootCmd = &cobra.Command{
	Use:   "funURL",
	Short: "A Swiss Army Knife for URLs",
-	Long: GetBanner() + `
+	Long: `
funURL is a command-line tool designed as a Swiss Army knife for URL. 
It takes a URL as input (via stdin, command-line flags, or arguments) and provides 
a range of operations for parsing, validation, modification, encoding/decoding, 
and handling URLs efficiently.`,
+	PersistentPreRun: func(cmd *cobra.Command, args []string) {
+		PrintBanner()
+	},
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3ed015 and dff6ecd.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • go.mod (1 hunks)
  • internal/cli/root.go (1 hunks)
🔇 Additional comments (3)
go.mod (2)

5-8: LGTM: Proper dependency management for colorized output.

The addition of github.com/fatih/color in a structured require block looks good. This is a popular package for adding terminal colors in Go applications.


12-15:

Details

✅ Verification successful

Verify indirect dependencies are compatible.

These indirect dependencies were automatically added to support the color package. Make sure they don't cause compatibility issues with your minimum Go version requirement.


🏁 Script executed:

#!/bin/bash
# Check if these indirect dependencies have any compatibility issues
go mod verify
echo "Go version compatibility check:"
go version

Length of output: 154


🏁 Script executed:

#!/bin/bash
# Extract minimum Go version declared in go.mod
grep '^go ' go.mod

Length of output: 30


All indirect dependencies verified successfully

  • go mod verify completed without errors
  • Project’s minimum Go version (go 1.24.1) matches the current Go toolchain
  • No compatibility issues detected with the listed indirect dependencies
internal/cli/root.go (1)

3-8: LGTM: Clean import organization.

The imports are well-organized with standard libraries first, followed by third-party packages.

Comment on lines +21 to +33
func GetBanner() string {
green := color.New(color.FgGreen).SprintFunc()
reset := color.New(color.Reset).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
fmt.Println(reset(`
__ _ _ ___ _
/ _|_ _ _ _ | | | | _ \ |
| _| || | ' \| |__| | / |__
|_| \_,_|_||_|____|_|_|_\____|`))
fmt.Printf(" %s <3 %s \n", green("A Swiss Army Knife for URLs"), red("@HappyHackingSpace"))
fmt.Println(reset(""))
return ""
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve function naming and consider environment detection.

The function name GetBanner() suggests it returns the banner as a string, but it actually prints to stdout and returns an empty string.

Consider these improvements:

  1. Rename the function to PrintBanner() to match its behavior
  2. Add terminal detection to avoid printing in non-interactive environments
-func GetBanner() string {
+func PrintBanner() {
	green := color.New(color.FgGreen).SprintFunc()
	reset := color.New(color.Reset).SprintFunc()
	red := color.New(color.FgRed).SprintFunc()
+	
+	// Skip banner in non-interactive environments
+	if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
+		return
+	}
+	
	fmt.Println(reset(`
   __           _    _ ___ _    
  / _|_  _ _ _ | |  | | _ \ |   
 |  _| || | ' \| |__| |   / |__ 
 |_|  \_,_|_||_|____|_|_|_\____|`))
	fmt.Printf(" %s <3 %s \n", green("A Swiss Army Knife for URLs"), red("@HappyHackingSpace"))
	fmt.Println(reset(""))	
-	return ""
}

Committable suggestion skipped: line range outside the PR's diff.

@omarkurt omarkurt changed the title add GetBanner function for enhanced CLI output add GetBanner function for enhanced CLI output and double decode/encode func Apr 25, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
internal/cli/encode.go (1)

19-19: Consider error handling for flag retrieval.

The error from GetBool is being discarded with the blank identifier. Although this follows the pattern of existing code, it's generally a good practice to check for errors when retrieving flag values, especially for flags that significantly affect program behavior.

-		doubled, _ := cmd.Flags().GetBool("double")
+		doubled, err := cmd.Flags().GetBool("double")
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "Error retrieving double flag: %v\n", err)
+			os.Exit(1)
+		}
internal/cli/decode.go (2)

19-19: Consider error handling for flag retrieval.

Similar to the encode.go file, the error from GetBool is being discarded. It would be more robust to check for errors when retrieving flag values.

-		doubled, _ := cmd.Flags().GetBool("double")
+		doubled, err := cmd.Flags().GetBool("double")
+		if err != nil {
+			fmt.Fprintf(os.Stderr, "Error retrieving double flag: %v\n", err)
+			os.Exit(1)
+		}

43-73: Consider adding documentation for expected input format.

When using double decoding, users might not always know if their input is double-encoded. Consider adding documentation (either in the code comments or CLI help text) to clarify when double decoding should be used and what types of input it expects.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dff6ecd and 224ec9f.

📒 Files selected for processing (2)
  • internal/cli/decode.go (2 hunks)
  • internal/cli/encode.go (2 hunks)
🔇 Additional comments (7)
internal/cli/encode.go (3)

41-41: LGTM! Good addition of the double encoding flag.

The flag is properly defined with a clear description and follows the naming pattern of the existing flags.


44-44: Function signature update is correct.

The function signature has been properly updated to accept the new parameter.


49-50: Double encoding implementation looks good.

The logic for double encoding is correctly implemented, using url.QueryEscape twice. This aligns with the description and purpose of the feature.

internal/cli/decode.go (4)

40-40: Good addition of the double decoding flag.

The flag is properly defined with a clear description and follows the existing pattern.


43-43: Function signature update is correct.

The function signature has been properly updated to accept the new parameter.


46-58: Good implementation of double decoding with proper error handling.

The double decoding implementation is well-structured with:

  1. Clear comments indicating the first and second pass
  2. Specific error messages for each decoding stage
  3. Proper error handling that exits on failure

This makes debugging easier if decoding fails at either stage.


59-64: Improved error messages for better debugging.

The error messages are now more specific about what kind of decoding failed (query component or path), which will make debugging easier. This is a good improvement over generic error messages.

Also applies to: 67-70

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
README.md (1)

15-17: ⚠️ Potential issue

Update installation instructions to reflect removal of install.sh
The install.sh script was removed in this PR, but the README still references it. Please replace it with the new Makefile workflow (e.g., make build) or add an install target as suggested above.

-./install.sh
+make build
+# then optionally: sudo cp funURL /usr/local/bin
🧹 Nitpick comments (4)
Makefile (4)

1-5: Consider adding an explicit install target and clarifying install paths
You define INSTALL_DIR (and USER_BIN) but don’t actually provide an install target. Adding one will streamline adoption, and you can document that writing to /usr/local/bin typically requires elevated privileges (or suggest using $(USER_BIN) for user‐local installs).

You could add something like:

+install:
+	@echo "Installing $(BINARY_NAME) to $(INSTALL_DIR)..."
+	@mkdir -p $(INSTALL_DIR)
+	@cp $(BINARY_NAME) $(INSTALL_DIR)
+	@echo "Installed $(BINARY_NAME) to $(INSTALL_DIR)"

10-19: Use printf for consistent ANSI escape handling
Relying on plain echo may not interpret \033 escapes portably across shells. Switching to printf (which reliably handles \n and escape sequences) will produce consistent colored output.

-	@echo "\033[0;32m"
+	@printf "\033[0;32m\n"
...
-	@echo "\033[0m"
+	@printf "\033[0m\n"

20-32: Simplify OS detection using go env and widen Windows support
uname -s may report MINGW64_NT-... or CYGWIN_NT-... on Windows, so the current check could miss those. You can use GOOS := $(shell go env GOOS) for reliable detection (windows, linux, darwin) and then branch accordingly. This also makes cross-compilation logic clearer.


33-41: Clean up all generated artifacts in one step
Right now you remove only the OS-specific binary. If you ever cross-compile or switch targets, remnants may remain. You can simplify to a single command that removes both names:

-ifeq ($(OS), Windows_NT)
-	@rm -f $(BINARY_NAME).exe
-else
-	@rm -f $(BINARY_NAME)
-endif
+	@rm -f $(BINARY_NAME) $(BINARY_NAME).exe
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 224ec9f and 70da339.

⛔ Files ignored due to path filters (2)
  • img/hhs.svg is excluded by !**/*.svg
  • img/image.png is excluded by !**/*.png
📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • README.md (2 hunks)
  • install.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • install.sh
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

5-5: Images should have alternate text (alt text)
null

(MD045, no-alt-text)

🔇 Additional comments (3)
README.md (3)

1-2: Top badge image and alt text look good
The “Made with love” badge includes meaningful alt text for accessibility. Nice!


8-10: Requirements section is clear and concise
Specifying “Golang 1.18+” aligns with the module’s Go version. No changes needed here.


124-125: Closing image alt text is present and correct
The bottom image includes the same meaningful alt text as the top badge. All good!

Comment on lines +6 to +7
.PHONY: all build clean

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add banner to .PHONY so it always runs
The banner target isn’t declared phony, so if a file named banner exists, Make will skip it. Including it in .PHONY ensures the ASCII art always prints.

-.PHONY: all build clean
+.PHONY: all banner build clean
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.PHONY: all build clean
.PHONY: all banner build clean


# funURL

<img src="img/image.png"> <br>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add descriptive alt text for the inline illustration
The <img src="img/image.png"> lacks alt text, which is important for accessibility and linting (MD045).

-<img src="img/image.png"> <br>
+<img src="img/image.png" alt="funURL usage illustration"> <br>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<img src="img/image.png"> <br>
<img src="img/image.png" alt="funURL usage illustration"> <br>
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

5-5: Images should have alternate text (alt text)
null

(MD045, no-alt-text)

@recepgunes1
Copy link
Member

great work! looks nice

@recepgunes1 recepgunes1 merged commit 53776d0 into HappyHackingSpace:main Apr 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants