Skip to content

Commit

Permalink
fix!: Rename CLI options to account and token_id
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed Oct 26, 2021
1 parent 2cdae4e commit aea4244
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ assert_eq!(res.unwrap(), [Price { internalid: "24".into(), unitprice: "95.49".in
Get all prices via SuiteQL.

```bash
export ACCOUNT_ID=<6 chars>;
export ACCOUNT=<6 chars>;
export CONSUMER_KEY=<64 chars>;
export CONSUMER_SECRET=<64 chars>;
export TOKEN_KEY=<64 chars>;
export TOKEN_ID=<64 chars>;
export TOKEN_SECRET=<64 chars>;
netsuite suiteql 'SELECT * FROM pricing'
```
18 changes: 9 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use clap::Parser;
#[clap(name = "netsuite", version = "abc123")]
struct Opts {
#[clap(short, long, env)]
account_id: String,
account: String,
#[clap(short = 'c', long, env)]
consumer_key: String,
#[clap(short = 'C', long, env)]
consumer_secret: String,
#[clap(short = 't', long, env)]
token_key: String,
token_id: String,
#[clap(short = 'T', long, env)]
token_secret: String,
#[clap(subcommand)]
Expand All @@ -36,17 +36,17 @@ enum SubCommand {
pub fn run() -> Result<(), Error> {
env_logger::init();

let opts = Opts::parse();
let cli_opts = Opts::parse();
let config = Config::new(
&opts.account_id,
&opts.consumer_key,
&opts.consumer_secret,
&opts.token_key,
&opts.token_secret,
&cli_opts.account,
&cli_opts.consumer_key,
&cli_opts.consumer_secret,
&cli_opts.token_id,
&cli_opts.token_secret,
);
let api = RestApi::new(&config);

match &opts.subcmd {
match &cli_opts.subcmd {
SubCommand::SuiteQl {
query,
limit,
Expand Down
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use crate::oauth1;

pub struct Config<'a> {
pub account_id: &'a str,
pub account: &'a str,
pub consumer: oauth1::Token<'a>,
pub token: oauth1::Token<'a>,
}

impl<'a> Config<'a> {
pub fn new(
account_id: &'a str,
account: &'a str,
consumer_key: &'a str,
consumer_secret: &'a str,
token_key: &'a str,
token_id: &'a str,
token_secret: &'a str,
) -> Self {
Self {
account_id,
account,
consumer: oauth1::Token::new(consumer_key, consumer_secret),
token: oauth1::Token::new(token_key, token_secret),
token: oauth1::Token::new(token_id, token_secret),
}
}
}
2 changes: 1 addition & 1 deletion src/requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> Requester<'a> {
&self.config.consumer,
Some(&self.config.token),
params.clone().map(|p| p.into()),
Some(self.config.account_id),
Some(self.config.account),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/rest_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct RestApi<'a> {

impl<'a> RestApi<'a> {
pub fn new(config: &'a Config) -> Self {
let base_url = DEFAULT_BASE_URL.replace("{}", config.account_id);
let base_url = DEFAULT_BASE_URL.replace("{}", config.account);
let requester = Requester::new(config, base_url);
let suiteql = SuiteQl::new(requester);
Self { suiteql }
Expand Down

0 comments on commit aea4244

Please sign in to comment.