Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

This pull request adds the ability to specify default values for the GetOrReadArgument methods in ConsoleHelpers, addressing issue #66.

🚀 New Features

  • GetOrReadArgumentOrDefault(int index, string defaultValue, params string[] args): Simple overload that returns the default value when argument is not found and user provides empty input
  • GetOrReadArgumentWithDefault(int index, string readMessage, string defaultValue, params string[] args): Full-featured method with custom prompt message and default value support

✅ Implementation Details

  • Backward Compatibility: All existing GetOrReadArgument methods remain unchanged and fully functional
  • Smart Default Handling: When an argument is missing from the args array and user provides empty input (or just presses Enter), the specified default value is returned
  • Null Safety: Handles null default values gracefully by returning empty string
  • Consistent Behavior: Maintains the same string processing (trimming, quote removal) as existing methods

🧪 Testing

  • Added comprehensive unit tests covering all scenarios:
    • Existing argument retrieval (should ignore default value)
    • Missing argument with default value
    • Custom message with default value
    • Null default value handling
    • Input processing (quotes, whitespace)

📖 Usage Examples

// Simple usage with default value
var filename = ConsoleHelpers.GetOrReadArgumentOrDefault(0, "default.txt", args);

// Custom message with default value
var timeout = ConsoleHelpers.GetOrReadArgumentWithDefault(1, "Enter timeout in seconds", "30", args);

🔧 Fixes

Closes #66


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #66
@konard konard self-assigned this Sep 13, 2025
- Add GetOrReadArgumentOrDefault method for simple cases with default value
- Add GetOrReadArgumentWithDefault method for cases with custom message and default value
- Both methods return the default value when argument is not found and user input is empty
- Maintain backward compatibility with existing GetOrReadArgument methods
- Add comprehensive tests for new functionality
- Add example demonstrating the new default value capabilities

Fixes #66

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add an ability to specify default value Add ability to specify default value for GetOrReadArgument methods Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 10:20
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>'
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.

Add an ability to specify default value

2 participants