Skip to content

Commit

Permalink
Fix global flag recognition in switch command
Browse files Browse the repository at this point in the history
- Implement manual flag checking for --global and -g flags
- Add debug logging to track argument parsing and flag detection
- Modify switchUser function to accept isGlobal as a parameter
- Improve error messages for better user guidance
- Enhance debug output for easier troubleshooting

This commit resolves an issue where the --global flag was not being
recognized in the switch command, causing incorrect behavior when
attempting to switch global Git identities.
  • Loading branch information
Test Name committed Aug 21, 2024
1 parent f51fde0 commit 9ab10a1
Show file tree
Hide file tree
Showing 4 changed files with 330 additions and 132 deletions.
44 changes: 34 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,51 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.3] - 2024-08-20

### Added
- Verbose mode with --verbose flag for detailed command execution information
- Command aliases for improved usability:
- `add` for `create`
- `use` for `switch`
- `remove` for `delete`
- `ls` for `list`
- New configuration command to set default behaviors (e.g., --always-global)
- CONTRIBUTING.md file with development guidelines

### Changed
- Improved flag parsing and error handling for all commands
- Enhanced error messages with contextual information and usage hints
- Updated README with clearer explanations of local vs global operations and more examples
- Restructured commands into separate functions for better code organization

### Fixed
- Resolved issue with global flag recognition in the switch command

### Improved
- Input validation across all commands
- User guidance in error messages, suggesting correct usage and next steps

## [0.0.2] - 2024-08-20

### Changed
- Improved error handling and debug logging
- Updated version number

## [0.0.1] - 2024-08-20

### Added
- Initial release of chicle
- Create command for generating SSH keys and creating Git identities
- Support for adding existing SSH keys when creating a new identity
- New --key flag in the create command to specify an existing SSH key
- Validation of existing SSH keys before adding them to an identity
- Switch command for changing Git user configurations
- Delete command to remove Git identities by alias
- List command to display all stored identities
- Persistent storage of user configurations
- Alias support for creating and switching between Git identities
- Global and local identity management
- Unique alias protection across global and local scopes
- Version checking functionality (--version flag)
- README.md with comprehensive usage instructions
- CHANGELOG.md to track changes
- README.md with usage instructions
- MIT License

### Changed
- The tool is now called chicle (previously had a different name)

[0.0.3]: https://github.com/permadart/chicle/compare/v0.0.2...v0.0.3
[0.0.2]: https://github.com/permadart/chicle/compare/v0.0.1...v0.0.2
[0.0.1]: https://github.com/permadart/chicle/releases/tag/v0.0.1
71 changes: 71 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Contributing to chicle

First off, thank you for considering contributing to chicle!

## Code of Conduct

By participating in this project, you are expected to remain civil.

## How Can I Contribute?

### Reporting Bugs

This section guides you through submitting a bug report for chicle. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports.

- Use a clear and descriptive title for the issue to identify the problem.
- Describe the exact steps which reproduce the problem in as many details as possible.
- Provide specific examples to demonstrate the steps.

### Suggesting Enhancements

This section guides you through submitting an enhancement suggestion for chicle, including completely new features and minor improvements to existing functionality.

- Use a clear and descriptive title for the issue to identify the suggestion.
- Provide a step-by-step description of the suggested enhancement in as many details as possible.
- Provide specific examples to demonstrate the steps or point out the part of chicle which the suggestion is related to.
- Explain why this enhancement would be useful to most chicle users.

### Your First Code Contribution

Unsure where to begin contributing to chicle? You can start by looking through these `beginner` and `help-wanted` issues:

- [Beginner issues](https://github.com/permadart/chicle/labels/beginner) - issues which should only require a few lines of code, and a test or two.
- [Help wanted issues](https://github.com/permadart/chicle/labels/help%20wanted) - issues which should be a bit more involved than `beginner` issues.

### Pull Requests

- Fill in the required template
- Do not include issue numbers in the PR title
- Include screenshots and animated GIFs in your pull request whenever possible.
- Follow the [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
- End all files with a newline

## Styleguides

### Git Commit Messages

- Use the present tense ("Add feature" not "Added feature")
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
- Limit the first line to 72 characters or less
- Reference issues and pull requests liberally after the first line

### Go Styleguide

All Go code is linted with [golangci-lint](https://golangci-lint.run/).

## Additional Notes

### Issue and Pull Request Labels

This section lists the labels we use to help us track and manage issues and pull requests.

- `bug` - Issues for bugs in the code
- `enhancement` - Issues for new features or improvements
- `documentation` - Issues related to documentation
- `good first issue` - Good for newcomers

## Getting Help

If you need help, you can ask questions on our [issues page](https://github.com/permadart/chicle/issues).

Thank you for contributing to chicle!
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ chicle is a platform-agnostic command-line tool for managing multiple Git identi
- Ensures unique aliases across global and local identities
- Supports both global and repository-specific identity management
- Version checking functionality
- Verbose mode for detailed output

## Installation

Expand Down Expand Up @@ -47,12 +48,31 @@ If you prefer to install from source or Homebrew is not available:

## Usage

### Global vs Local Operations

chicle supports both global and local Git identity management:

- Global identities are used across all Git repositories on your system.
- Local identities are specific to a single Git repository.

When using local operations, ensure you're in a Git repository. For global operations, use the `--global` flag or the appropriate subcommand.

### Verbose Mode

To enable detailed output for any command, use the `--verbose` or `-V` flag:

```bash
chicle --verbose [command]
```

### Create a new SSH key and identity (globally)

```bash
chicle create --alias user1 --email [email protected] --name "John Doe" --global
```

Alias: `chicle add`

### Create a new SSH key and identity (for the current repository)

```bash
Expand All @@ -77,18 +97,24 @@ chicle create --alias user2 --email [email protected] --name "Jane Doe" --key ~/
chicle switch user1 --global
```

Aliases: `chicle use`, `chicle switch-global`

### Switch Git user (for the current repository)

```bash
chicle switch user1
```

Alias: `chicle switch-local`

### Delete a Git identity (globally)

```bash
chicle delete user1 --global
```

Alias: `chicle remove`

### Delete a Git identity (local)

```bash
Expand All @@ -101,6 +127,14 @@ chicle delete user1
chicle list
```

Alias: `chicle ls`

### Configure default behaviors

```bash
chicle config --always-global
```

### Check chicle version

```bash
Expand All @@ -113,14 +147,24 @@ chicle -v

## Important Notes

- When creating or switching to a local identity (without the `--global` flag), you must be inside a Git repository. If you're not in a Git repository, chicle will return an error and prompt you to use the `--global` flag.
- When creating or switching to a local identity, you must be inside a Git repository. If you're not in a Git repository, chicle will return an error and prompt you to use the `--global` flag.
- Aliases must be unique across both global and local identities. chicle will prevent you from creating an identity with an alias that already exists in either scope.
- The `list` command shows both global and local identities separately for better clarity.
- When switching identities, chicle clears existing SSH keys from the agent before adding the new one to ensure a clean switch.

## Error Messages and Troubleshooting

chicle provides informative error messages to guide you:

- If you're not in a Git repository for local operations, you'll be prompted to use the `--global` flag or navigate to a Git repository.
- If an alias already exists, you'll be informed and asked to choose a different alias.
- If an identity is not found during switch or delete operations, you'll be prompted to use the `list` command to see available identities.

For more detailed output, use the `--verbose` flag with any command.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines on how to contribute to this project.

## License

Expand Down
Loading

0 comments on commit 9ab10a1

Please sign in to comment.