Skip to content

Commit

Permalink
better split between cli app and lib - 2nd step
Browse files Browse the repository at this point in the history
  • Loading branch information
sycured committed Aug 11, 2023
1 parent fe18fa7 commit 6e4f957
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 139 deletions.
2 changes: 1 addition & 1 deletion src/cli/group/cli_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use clap::ArgMatches;
use rayon::prelude::*;

use jira_cli::{Global, library::group};
use jira_cli::{group, Global};

Check failure on line 11 in src/cli/group/cli_logic.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `jira_cli`

pub fn add_user(global: &Global, args: &ArgMatches) {
let account_ids: Vec<&String> = args
Expand Down
3 changes: 1 addition & 2 deletions src/cli/issue/cli_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use clap::ArgMatches;
use rayon::prelude::*;

use jira_cli::{Global, library::issue};

use jira_cli::{issue, Global};

Check failure on line 11 in src/cli/issue/cli_logic.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `jira_cli`

pub fn add_label(global: &Global, args: &ArgMatches) {
let issue_keys: Vec<&String> = args
Expand Down
5 changes: 3 additions & 2 deletions src/cli/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

use clap::{Arg, ArgMatches, Command};

use jira_cli::labels::list;

Check failure on line 10 in src/cli/labels.rs

View workflow job for this annotation

GitHub Actions / Check

failed to resolve: use of undeclared crate or module `jira_cli`

use crate::Global;
use jira_cli::library::labels::list_labels;

pub fn cli_commands() -> Command {
Command::new("labels")
Expand All @@ -29,7 +30,7 @@ pub fn cli_commands() -> Command {
}

pub fn logic_commands(global: &Global, args: &ArgMatches) {
list_labels(
list(
global.domain.as_str(),
global.user.as_str(),
global.token.as_str(),
Expand Down
10 changes: 5 additions & 5 deletions src/cli.rs → src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* SPDX-License-Identifier: GPL-2.0-only
*/

use clap::{
crate_authors, crate_description, crate_name, crate_version, value_parser, Arg, Command,
};
use clap_complete::Shell;

pub mod check_version;
pub mod group;
pub mod issue;
Expand All @@ -18,6 +13,11 @@ pub mod license;
pub mod project;
pub mod user;

use clap::{
crate_authors, crate_description, crate_name, crate_version, value_parser, Arg, Command,
};
use clap_complete::Shell;

fn generate() -> Command {
Command::new("generate")
.about("Generate autocompletion script for your shell")
Expand Down
4 changes: 2 additions & 2 deletions src/cli/project/cli_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use clap::ArgMatches;
use rayon::prelude::*;

use jira_cli::{Global, library::project};
use jira_cli::{project, Global};

Check failure on line 11 in src/cli/project/cli_logic.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `jira_cli`

pub fn create(global: &Global, args: &ArgMatches) {
project::create(
Expand All @@ -24,7 +24,7 @@ pub fn create(global: &Global, args: &ArgMatches) {
}

pub fn delete_project(global: &Global, args: &ArgMatches) {
project::delete_project(
project::delete(
global,
args.get_one::<String>("project_key").unwrap().as_str(),
);
Expand Down
3 changes: 2 additions & 1 deletion src/cli/user/cli_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

use clap::ArgMatches;
use jira_cli::{Global, library::user};

use jira_cli::{user, Global};

Check failure on line 10 in src/cli/user/cli_logic.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `jira_cli`

pub fn create(global: &Global, args: &ArgMatches) {
user::create(
Expand Down
114 changes: 0 additions & 114 deletions src/lib.rs

This file was deleted.

7 changes: 6 additions & 1 deletion src/library/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use comfy_table::{Cell, CellAlignment};
use rayon::prelude::*;
use serde_json::{json, Value};

use crate::{confirm, create_and_print_table, delete_request, get_request, post_request, library::urls::URLS, Global};
use crate::{
confirm, create_and_print_table, delete_request, get_request, post_request, urls::URLS, Global,
};

pub fn add_user(global: &Global, account_id: &str, group_id: &str) {
let url: String = format!(
Expand Down Expand Up @@ -62,6 +64,7 @@ pub fn delete(global: &Global, group_id: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn find(global: &Global, query: &str) {
let url: String = format!(
"https://{}{}/picker?query={query}",
Expand Down Expand Up @@ -95,6 +98,7 @@ pub fn find(global: &Global, query: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn list_groups(global: &Global, start_at: &str, max_results: &str) {
let url: String = format!(
"https://{}{}/bulk?startAt={start_at}&maxResults={max_results}",
Expand Down Expand Up @@ -128,6 +132,7 @@ pub fn list_groups(global: &Global, start_at: &str, max_results: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn list_users(
global: &Global,
group_id: &str,
Expand Down
15 changes: 13 additions & 2 deletions src/library/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use comfy_table::{Cell, CellAlignment};
use rayon::prelude::*;
use serde_json::{json, Value};

use crate::{create_and_print_table, delete_request, Global, get_request, post_request, put_request,library::urls::URLS};
use crate::{
create_and_print_table, delete_request, get_request, post_request, put_request, urls::URLS,
Global,
};

pub fn add_label(global: &Global, issue_key: &str, label: &str) {
let url: String = format!("https://{}{}/{issue_key}", global.domain, URLS["issue"]);
Expand Down Expand Up @@ -84,7 +87,7 @@ pub fn assign(global: &Global, issue_key: &str, account_id: &str, success_messag
}
}

#[allow(clippy::too_many_arguments)]
#[allow(clippy::missing_panics_doc)]
pub fn create(
global: &Global,
reporter_account_id: &str,
Expand Down Expand Up @@ -125,6 +128,7 @@ pub fn create(
}
}

#[allow(clippy::missing_panics_doc)]
pub fn create_link_type(global: &Global, name: &str, inward: &str, outward: &str) {
let url: String = format!("https://{}{}", global.domain, URLS["issue_link_types"]);
let payload: Value = json!({
Expand Down Expand Up @@ -185,6 +189,7 @@ pub fn delete_link_type(global: &Global, link_type_id: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn get_link_type(global: &Global, link_type_id: &str) {
let url: String = format!(
"https://{}{}/{link_type_id}",
Expand Down Expand Up @@ -222,6 +227,7 @@ pub fn get_link_type(global: &Global, link_type_id: &str) {
}
}

#[allow(clippy::missing_panics_doc)]
pub fn get_transitions(global: &Global, issue_key: &str) {
let url: String = format!(
"https://{}{}/{issue_key}/transitions",
Expand Down Expand Up @@ -260,6 +266,7 @@ pub fn get_transitions(global: &Global, issue_key: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn list_link_types(global: &Global) {
let url: String = format!("https://{}{}", global.domain, URLS["issue_link_types"]);
match get_request(&url, global.user.as_str(), global.token.as_str()) {
Expand Down Expand Up @@ -296,6 +303,7 @@ pub fn list_link_types(global: &Global) {
}
}

#[allow(clippy::missing_panics_doc)]
pub fn list_priorities(global: &Global) {
let url: String = format!("https://{}{}", global.domain, URLS["priority"]);
match get_request(&url, global.user.as_str(), global.token.as_str()) {
Expand All @@ -312,6 +320,7 @@ pub fn list_priorities(global: &Global) {
}
}

#[allow(clippy::missing_panics_doc)]
pub fn list_types(global: &Global, project_key: &str) {
let url: String = format!(
"https://{}{}/createmeta?projectKeys={project_key}",
Expand All @@ -336,6 +345,7 @@ pub fn list_types(global: &Global, project_key: &str) {
}

//noinspection DuplicatedCode
#[allow(clippy::missing_panics_doc)]
pub fn list_votes(global: &Global, issue_key: &str) {
let url: String = format!(
"https://{}{}/{issue_key}/votes",
Expand Down Expand Up @@ -435,6 +445,7 @@ pub fn remove_vote(global: &Global, issue_key: &str) {
}
}

#[allow(clippy::missing_panics_doc)]
pub fn show_fixversions(global: &Global, issue_key: &str) {
let url: String = format!("https://{}{}/{issue_key}", global.domain, URLS["issue"]);
match get_request(&url, global.user.as_str(), global.token.as_str()) {
Expand Down
7 changes: 5 additions & 2 deletions src/library/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
*/

use std::process::exit;

use rayon::prelude::*;
use serde_json::Value;
use crate::{get_request, library::urls::URLS};

pub fn list_labels(domain: &str, user: &str, token: &str, start_at: &str, max_results: &str) {
use crate::{get_request, urls::URLS};

#[allow(clippy::missing_panics_doc)]
pub fn list(domain: &str, user: &str, token: &str, start_at: &str, max_results: &str) {
let url: String = format!(
"https://{}{}?startAt={}&maxResults={}",
domain, URLS["label"], start_at, max_results
Expand Down
2 changes: 2 additions & 0 deletions src/library/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* SPDX-License-Identifier: GPL-2.0-only
*/

#![forbid(unsafe_code)]

pub mod group;
pub mod issue;
pub mod labels;
Expand Down
Loading

0 comments on commit 6e4f957

Please sign in to comment.