diff --git a/Cargo.toml b/Cargo.toml index 7f769f9..01a12fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kutt" -version = "0.0.1" +version = "0.0.2" authors = ["mahdi "] edition = "2018" description = "command line tool for kutt.it service" diff --git a/README.md b/README.md index 94a3e77..e5ada51 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,24 @@ OPTIONS: -p, --password Set a password -t, --target-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; diff --git a/src/api.rs b/src/api.rs index 5d2ce2e..e300b68 100644 --- a/src/api.rs +++ b/src/api.rs @@ -79,7 +79,6 @@ impl Kutt { eprintln!("{}", e); Error::ParseJsonError })?; - println!("{:#?}", response); Ok(response.short_url) } pub fn delete_link(short_link: &str) -> Result { diff --git a/src/constants.rs b/src/constants.rs index e4dd8f3..d3f299b 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -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 !"); } diff --git a/src/main.rs b/src/main.rs index 1154117..31991eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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), } }