Skip to content

Commit

Permalink
chore: upgrade momento sdk - consistency, less copypasta (#150)
Browse files Browse the repository at this point in the history
This change establishes a common pattern for interacting with the
service. Rather than copy/pasting matches, MomentoError -> CliError
mapping and json dump code around, this names those functionalities
as functions:
* interact_with_momento: Completes a momento future and maps the
  result to a Result< HappyCaseType, CliError >
* print_whatever_this_is_as_json: prints whatever you feed it as json
* drop windows lint, linux lint is enough
* also choco install protoc in a windows build near you. Relates to tokio-rs/prost#620

This change was precipitated by the change in the SDK to simplify
and coalesce client creation behind the SimpleCacheClientBuilder and
triggered by the SDK upgrade.

There are small changes to debug and error messages, but this change
should cause no functional changes.

tired of copypasta.
```
pub async fn delete_cache(cache_name: String, auth_token: String) -> Result<(), CliError> {
    debug!("deleting cache...");
    let mut momento = get_momento_client(auth_token).await?;
    match momento.delete_cache(&cache_name).await {
        Ok(_) => (),
        Err(e) => return Err(CliError { msg: e.to_string() }),
    };
    Ok(())
}
```
becomes
```
pub async fn delete_cache(cache_name: String, auth_token: String) -> Result<(), CliError> {
    let mut client = get_momento_client(auth_token).await?;
    interact_with_momento("deleting cache...", client.delete_cache(&cache_name)).await
}
```
  • Loading branch information
kvcache authored May 21, 2022
1 parent c2eec9c commit 893c4d1
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 254 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ jobs:
needs: release
steps:
- uses: actions/checkout@v2
- name: i guess windows-latest does not have protoc or cmake but we need protoc
run: choco install protoc
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ jobs:
- name: Rigorous lint via Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

rustfmt-windows:
name: Style & Lint - Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: rustfmt
run: cargo fmt -- --check
- name: Rigorous lint via Clippy
run: cargo clippy --all-targets --all-features -- -D warnings

build:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -79,6 +69,8 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: i guess windows-latest does not have protoc or cmake but we need protoc
run: choco install protoc
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
Loading

0 comments on commit 893c4d1

Please sign in to comment.