Skip to content

Commit

Permalink
msg for login
Browse files Browse the repository at this point in the history
  • Loading branch information
robatipoor committed Jun 25, 2019
1 parent fb4f453 commit 97eca16
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kutt"
version = "0.0.1"
version = "0.0.2"
authors = ["mahdi <[email protected]>"]
edition = "2018"
description = "command line tool for kutt.it service"
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,24 @@ OPTIONS:
-p, --password <PASSWORD> Set a password
-t, --target-url <URL> Set a url
```
## set apikey
```sh
kutt --login your-api-key
# or
export KUTT_API_KEY="your-api-key"
```
## example
```sh
kutt --target-url https://github.com/ --custom-url your-domain
# or
echo "https://github.com/" | kutt -c your-domain
```

## How to use crate
```sh
cargo add kutt
```
```rs
```rust
extern crate dotenv;
extern crate kutt;

Expand Down
1 change: 0 additions & 1 deletion src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl Kutt {
eprintln!("{}", e);
Error::ParseJsonError
})?;
println!("{:#?}", response);
Ok(response.short_url)
}
pub fn delete_link(short_link: &str) -> Result {
Expand Down
3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub const API_KEY_FILE_NAME: &str = ".kutt-api-key.txt";
pub const API_KEY_FILE_NAME: &str = "kutt-api-key.txt";
lazy_static! {
pub static ref PATH_FILE_API_KEY: PathBuf = home_dir().unwrap().join(API_KEY_FILE_NAME);
pub static ref KUTT_API_KEY: String = ApiKey::get().unwrap();
pub static ref KUTT_API_KEY: String = ApiKey::get()
.expect("you need to login with your api-key or set KUTT_API_KEY environment variable !");
}
21 changes: 17 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ fn main() {
return;
}
match read_from_stdin() {
Ok(link) => match Kutt::target_url(link.as_str()).reuse().create_short_link() {
Ok(o) => println!("{}", o),
Err(e) => fatal!(e),
},
Ok(link) => {
if app.custom_url.is_some() {
match Kutt::target_url(link.as_str())
.reuse()
.custom_url(app.custom_url.unwrap())
.create_short_link()
{
Ok(o) => println!("{}", o),
Err(e) => fatal!(e),
}
} else {
match Kutt::target_url(link.as_str()).reuse().create_short_link() {
Ok(o) => println!("{}", o),
Err(e) => fatal!(e),
}
}
}
Err(e) => fatal!(e),
}
}

0 comments on commit 97eca16

Please sign in to comment.