Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: adding config in CLI #39

Closed
wants to merge 105 commits into from
Closed

Feat: adding config in CLI #39

wants to merge 105 commits into from

Conversation

aaravm
Copy link
Collaborator

@aaravm aaravm commented Aug 12, 2024

Here, most of the code is copied #38, only getting config is added. Please merge this after #38.

Summary by Sourcery

Introduce a CLI tool for managing tasks using the TES API, add configuration support, implement TES and transport modules, and set up CI/CD workflows and documentation.

New Features:

  • Introduce a CLI tool with subcommands for creating, listing, getting, checking status, and canceling tasks using the TES API.
  • Add support for reading configuration from a JSON file to configure the CLI tool.

Enhancements:

  • Implement a new module for handling TES-related operations, including task creation, listing, retrieval, status checking, and cancellation.
  • Add a transport module to handle HTTP requests with support for GET, POST, PUT, and DELETE methods.

Build:

  • Add a build script (build-models.sh) to generate models using OpenAPI specifications.
  • Add a rustfmt configuration file to specify formatting rules and ignore certain directories.

CI:

  • Add GitHub Actions workflows for CI/CD, including caching dependencies, building the project, running tests, linting, and formatting.

Documentation:

  • Add a README file with instructions for building the project, running tests, and testing the CI/CD workflow locally.

Tests:

  • Add unit tests for TES operations, including task creation, status checking, cancellation, and listing.
  • Add a test utility module to ensure the Funnel server is running before executing tests.

Copy link
Contributor

sourcery-ai bot commented Aug 12, 2024

Reviewer's Guide by Sourcery

This pull request adds configuration functionality to the CLI and introduces several new files and modifications to existing ones. The changes primarily focus on implementing a configuration system, enhancing the CLI structure, and adding new utility functions. Key additions include a new main.rs file for the CLI, modifications to the TES module, and the introduction of configuration and transport-related files.

File-Level Changes

Files Changes
cli/src/main.rs Implemented a new CLI structure with subcommands for TES operations (create, list, get, status, cancel)
cli/src/main.rs
lib/src/configuration.rs
Added configuration loading functionality, including the ability to read from a config file
lib/src/transport.rs Introduced a Transport struct for handling HTTP requests
lib/src/tes/mod.rs Modified the TES module to use the new Transport and Configuration structs
lib/src/serviceinfo/mod.rs Added ServiceInfo module for handling service information requests
.github/workflows/local.yml
.github/workflows/ci.yml
Implemented CI/CD workflows for both local and GitHub environments
build-models.sh
run-tests.sh
Added utility scripts for building models and running tests
lib/src/test_utils.rs Introduced test utilities for setting up and running Funnel server
nextest.toml Added nextest configuration for improved test running

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

@aaravm aaravm closed this Aug 12, 2024
@aaravm
Copy link
Collaborator Author

aaravm commented Aug 12, 2024

accidently made pr with wrong branch

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @aaravm - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider replacing unwrap() calls in the CLI implementation with more robust error handling to improve the user experience when invalid input is provided.
  • There's some code duplication in the CLI command handling. Consider refactoring common patterns into shared functions to improve maintainability.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟡 Documentation: 3 issues found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Ok(config)
}

fn load_configuration() -> Configuration {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Improve error handling in configuration loading

The current implementation of load_configuration() doesn't handle potential errors very gracefully. Consider refactoring to provide more informative error messages and handle failure cases explicitly.

fn load_configuration() -> Result<Configuration, ConfigError> {
    let config_file_path = dirs::home_dir()
        .ok_or(ConfigError::HomeDirNotFound)?
        .join(".config/config.json");

endpoint: &str,
data: Option<Value>,
params: Option<Value>,
) -> Result<String, Box<dyn Error>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider using custom error types instead of Box

Using Box is quite generic. Consider creating custom error types to provide more specific and informative error handling throughout the application.

) -> Result<String, TransportError> {

// ... (elsewhere in the file)

#[derive(Debug, thiserror::Error)]
pub enum TransportError {
    #[error("URL parsing error: {0}")]
    UrlParseError(#[from] url::ParseError),
    #[error("Request error: {0}")]
    RequestError(#[from] reqwest::Error),
    // Add other specific error types as needed
}

@@ -0,0 +1,36 @@
# A Generic SDK and CLI for GA4GH API services
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (documentation): Consider capitalizing 'Services' for consistency.

To maintain a consistent title case format, consider changing 'services' to 'Services'.

```
cargo nextest run
```
For checking the unit converage, you can run:
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (documentation): Typo in the word 'converage'.

The word 'converage' should be corrected to 'coverage'.

```
bash ./run-tests.sh
```
or, you can run using cargo nextest using
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (documentation): Repetition of the word 'using'.

The phrase 'using cargo nextest using' should be rephrased to 'using cargo nextest'.

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