Explore.CLI - Progress
Tags: beginners, programming, csharp, dotnet
Published: 2023-12-09 15:52:57

Welcome back to the ongoing journey of enhancing [Explore.CLI](https://github.com/SmartBear-DevRel/explore-cli)! As I [discussed last week](https://dev.to/yousefmajidi/planning-more-enhancements-for-explorecli-5do9), my focus has been on implementing new features and refining existing ones. In this update, I am excited to share the progress made and the intricacies of the latest improvements.

## Enhancing the 'Import' Feature

Building upon the momentum of previous weeks, where I enhanced the `Export` feature, I turned my attention to the `Import` feature. The primary enhancement was the integration of the `--names` option, similar to what was done for `Export`. This required a few key updates:

- Modifying the `Option` variable `names` to indicate its dual functionality for both import and export.
- Adjusting the `importSpaceCommand` to correctly utilize the `names` option.
- Updating the `ImportSpaces` method to handle a comma-separated list of names.

The implementation ensures a more intuitive and flexible import process, catering to specific user needs.

## Code Refinement and Bug Fixing

In addition to feature enhancement, a significant part of my focus was on refining existing code and addressing bugs:

- **Removing Deprecated Features:** Following discussions on [issue #18](https://github.com/SmartBear-DevRel/explore-cli/issues/18), I removed the `import-inspector-collections` feature, ensuring the codebase remains streamlined and up-to-date.
- **Bug Fixing:** A small bug, [identified](https://github.com/SmartBear-DevRel/explore-cli/pull/17#issuecomment-1825865327) in my previous contributions, was addressed. The application now displays an appropriate message when no matching spaces are found during export or import, improving user experience.

### Code Snippets

Here's a glimpse of the key code changes implemented:

1. Modifying the `names` option:
```c#
var names = new Option<string>(name: "--names", description: "The names of the spaces to export or import") { IsRequired = false };
```

2. Adjusting `importSpaceCommand`:
```c#
var importSpacesCommand = new Command("import-spaces")
{
    exploreCookie,
    importFilePath,
    names,
    verbose
};

importSpacesCommand.SetHandler(async (ec, fp, v, n) =>
    { await ImportSpaces(ec, fp, v, n); },
    exploreCookie,
    importFilePath,
    names,
    verbose);
```

3. Implementing checks for matching spaces during import and export:
```c#
// For Export
if (namesList?.Count > 0 && space.Name != null && !namesList.Contains(space.Name))
{
    AnsiConsole.MarkupLine($"[orange3]'Skipped {space.Name}': Name not found in list of names to export[/]");
    continue;
}
// For Import
    foreach (var exportedSpace in exportedSpaces.ExploreSpaces)
{
    if (namesList?.Count > 0 && exportedSpace.Name != null && !namesList.Contains(exportedSpace.Name)) {
    AnsiConsole.MarkupLine($"[orange3]'Skipped {exportedSpace.Name}': Name not found in list of names to import[/]");
    continue;
    }
}
```

### Documentation and Pull Request

Finally, the `README.md` file was meticulously updated to reflect these changes, aiding future contributors and users. All these updates are encapsulated in a [pull request](https://github.com/SmartBear-DevRel/explore-cli/pull/19), which is currently under review. I have already addressed a minor typo pointed out by the repository owner and am eagerly awaiting the final approval.

### Conclusion

This phase of enhancements to Explore.CLI has been a blend of expansion, refinement, and learning. It demonstrates the project's commitment to continuous improvement and user-centric development. As always, I am keen to hear feedback and look forward to sharing more updates soon.