Skip to content

Commit

Permalink
feat: add cargo features (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrachev authored Feb 19, 2022
1 parent 77710de commit 73a46a3
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### 🚀 Added

### ⚙️ Changed

### 🛠 Fixed

## [v0.3.0] - 2022-02-19
### 🚀 Added
- Add cargo features [#26](https://github.com/mgrachev/update-informer/pull/26)
- Add configurable request timeout and interval [#24](https://github.com/mgrachev/update-informer/pull/24)
- Add PyPI support [#16](https://github.com/mgrachev/update-informer/pull/16) ([@itamarst](https://github.com/itamarst))
- Add logo [#19](https://github.com/mgrachev/update-informer/pull/19)
Expand All @@ -31,5 +39,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Check updates on GitHub [#8](https://github.com/mgrachev/update-informer/pull/8)
- Check updates on Crates.io [#1](https://github.com/mgrachev/update-informer/pull/1)

[v0.3.0]: https://github.com/mgrachev/update-informer/releases/tag/v0.3.0
[v0.2.0]: https://github.com/mgrachev/update-informer/releases/tag/v0.2.0
[v0.1.0]: https://github.com/mgrachev/update-informer/releases/tag/v0.1.0
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "update-informer"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Mikhail Grachev <[email protected]>"]
description = "Update informer for CLI applications"
Expand All @@ -20,3 +20,9 @@ ureq = { version = "2.4", features = ["json"] }
[dev-dependencies]
mockito = "0.30.0"
once_cell = "1.9.0"

[features]
default = ["crates"]
crates = []
github = []
pypi = []
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# Update-informer [![CI](https://github.com/mgrachev/update-informer/workflows/CI/badge.svg)](https://github.com/mgrachev/update-informer/actions) [![Crates.io](https://img.shields.io/crates/v/update-informer)](https://crates.io/crates/update-informer) [![docs.rs](https://img.shields.io/docsrs/update-informer)](https://docs.rs/update-informer) [![codecov](https://codecov.io/gh/mgrachev/update-informer/branch/main/graph/badge.svg?token=A4XD1DGFGJ)](https://codecov.io/gh/mgrachev/update-informer)
# Update-informer [![CI]](https://github.com/mgrachev/update-informer/actions) [![Crates.io]](https://crates.io/crates/update-informer) [![docs.rs]](https://docs.rs/update-informer) [![codecov]](https://codecov.io/gh/mgrachev/update-informer)

[CI]: https://github.com/mgrachev/update-informer/workflows/CI/badge.svg
[Crates.io]: https://img.shields.io/crates/v/update-informer
[docs.rs]: https://img.shields.io/docsrs/update-informer
[codecov]: https://codecov.io/gh/mgrachev/update-informer/branch/main/graph/badge.svg?token=A4XD1DGFGJ

[directories]: https://github.com/dirs-dev/directories-rs
[ureq]: https://github.com/algesten/ureq
[semver]: https://github.com/dtolnay/semver
[serde]: https://github.com/serde-rs/serde
[CLI application]: https://cli.github.com
[JavaScript library]: https://github.com/yeoman/update-notifier
[Update-informer]: https://evrone.com/update-informer?utm_source=github&utm_campaign=update-informer
[Evrone]: https://evrone.com/?utm_source=github&utm_campaign=update-informer
[MIT]: https://choosealicense.com/licenses/mit

<img align="right"
alt="update-informer"
Expand All @@ -11,22 +26,38 @@ It checks for a new version on Crates.io, GitHub and PyPI 🚀
## Benefits
* Support of **Crates.io**, **GitHub** and **PyPI**.
* Configurable **check frequency** and **request timeout**.
* **Minimum dependencies** - only [directories](https://github.com/dirs-dev/directories-rs), [ureq](https://github.com/algesten/ureq), [semver](https://github.com/dtolnay/semver) and [serde](https://github.com/serde-rs/serde).
* **Minimum dependencies** - only [directories], [ureq], [semver] and [serde].

The idea is actually not new, as GitHub has been doing for a long time in its [CLI application](https://cli.github.com).<br>
There is also a popular [JavaScript library](https://github.com/yeoman/update-notifier).
The idea is actually not new, as GitHub has been doing for a long time in its [CLI application].<br>
There is also a popular [JavaScript library].

[Update-informer](https://evrone.com/update-informer?utm_source=github&utm_campaign=update-informer) is created & supported by [Evrone](https://evrone.com/?utm_source=github&utm_campaign=update-informer).
[Update-informer] is created & supported by [Evrone].

## Usage

Add `update-informer` to `Cargo.toml`:

```toml
[dependencies]
update-informer = "0.2.0"
update-informer = "0.3.0"
```

By default, `update-informer` can only check on Crates.io.
To enable support for other registries, use `features`:

```toml
[dependencies]
update-informer = { version = "0.3.0", default_features = false, features = ["github"] }
```

Available features:

Name | Default?
---|---
cargo | Yes
github | No
pypi | No

## Crates.io

To check for a new version on Crates.io, use the `UpdateInformer::check_version` function.<br>
Expand Down Expand Up @@ -199,4 +230,4 @@ informer.check_version();

## License

[MIT](https://choosealicense.com/licenses/mit)
[MIT]
5 changes: 5 additions & 0 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ use crate::Error;
use serde::de::DeserializeOwned;
use std::time::Duration;

/// HTTP client
pub(crate) struct Client {
request: ureq::Request,
}

/// Initializes GET request
pub(crate) fn get(url: &str, timeout: Duration) -> Client {
Client {
request: ureq::agent().get(url).timeout(timeout),
}
}

impl Client {
#[allow(dead_code)] // Used only for GitHub
/// Adds HTTP header to request
pub(crate) fn add_header(mut self, key: &str, value: &str) -> Self {
self.request = self.request.set(key, value);
self
}

/// Sends a request and parses it to JSON
pub(crate) fn call<T: DeserializeOwned>(self) -> Result<T, Error> {
let json = self.request.call()?.into_json()?;

Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@
//!
//! ## Usage
//!
//! By default, `update-informer` can only check on [`Crates.io`].
//! To enable support for other registries, use `features`:
//!
//! ```toml
//! [dependencies]
//! update-informer = { version = "0.3.0", default_features = false, features = ["github"] }
//! ```
//!
//! Available features:
//!
//! Name | Default?
//! ---|---
//! cargo | Yes
//! github | No
//! pypi | No
//!
//! ## Crates.io
//!
//! To check for a new version on Crates.io, use the [`UpdateInformer::check_version`] function. This function takes the project name and current version:
//!
//! ```rust
Expand Down
10 changes: 10 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use crate::{Error, Package};
use std::time::Duration;

#[cfg(feature = "crates")]
pub use crates::Crates;

#[cfg(feature = "github")]
pub use github::GitHub;

#[cfg(feature = "pypi")]
pub use pypi::PyPI;

#[cfg(feature = "crates")]
mod crates;

#[cfg(feature = "github")]
mod github;

#[cfg(feature = "pypi")]
mod pypi;

pub trait Registry {
Expand Down

0 comments on commit 73a46a3

Please sign in to comment.