ConfigFile

Struct ConfigFile 

Source
pub struct ConfigFile { /* private fields */ }
Expand description

This struct holds the configuration data to use the Jira API (authentication info and Jira base_url).

Implementations§

Source§

impl ConfigFile

Implementation of ConfigFile

§Methods

  • new(auth_token: String, jira_url: String) -> ConfigFile - creates a new instance of ConfigFile
  • default() -> ConfigFile - creates a new instance of ConfigFile with default values
  • write_to_file(file: &str) -> Result<(), std::io::Error> - writes the ConfigFile to a file
  • read_from_file(file: &str) -> Result<ConfigFile, std::io::Error> - reads the ConfigFile from a file
  • get_auth() -> AuthSection - gets the AuthSection from the ConfigFile
  • get_jira() -> JiraSection - gets the JiraSection from the ConfigFile
  • set_auth(auth: AuthSection) - sets the AuthSection in the ConfigFile
  • set_jira(jira: JiraSection) - sets the JiraSection in the ConfigFile
  • set_standard_resolution(standard_resolution: String) - sets the standard_resolution in the ConfigFile
  • get_standard_resolution() -> String - gets the standard_resolution from the ConfigFile
  • set_standard_resolution_comment(standard_resolution_comment: String) - sets the standard_resolution_comment in the ConfigFile
  • get_standard_resolution_comment() -> String - gets the standard_resolution_comment from the Config
  • add_transition_name(key: String, value: String) - adds a transition_name to the ConfigFile
  • get_transition_name(key: &str) -> Option<String> - gets a transition_name from the ConfigFile
Source

pub fn new( auth_token: String, jira_url: String, standard_resolution: String, standard_resolution_comment: String, transitions_names: Table, ) -> ConfigFile

Create a new ConfigFile struct.

§Arguments
  • auth_token - The authentication token to be used with the Jira API.
  • jira_url - The base_url for the Jira API.
  • standard_resolution - The standard resolution to be used when resolving an issue.
  • standard_resolution_comment - The standard comment to be used when resolving an issue.
  • transitions_names - The transitions names to be used when transitioning an issue.
§Returns
  • A new ConfigFile struct.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());

assert_eq!(config.get_auth_key(), "auth_token");
assert_eq!(config.get_jira_url(), "jira_url");
assert_eq!(config.get_standard_resolution(), "standard_resolution");
assert_eq!(config.get_standard_resolution_comment(), "standard_resolution_comment");
Source

pub fn set_auth_key(&mut self, auth_token: String)

Set the authentication token for the ConfigFile struct. This is the token that will be used to authenticate with the Jira API.

§Arguments
  • auth_token - The authentication token to be used with the Jira API.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.set_auth_key("auth_key".to_string());

assert_eq!(config.get_auth_key(), "auth_key");
Source

pub fn get_auth_key(&self) -> &str

Get the authentication token for the ConfigFile struct. This is the token that will be used to authenticate with the Jira API. This is useful for getting the current value of the authentication token.

§Returns
  • The authentication token to be used with the Jira API.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());
let auth_key = config.get_auth_key();

assert_eq!(auth_key, "auth_token");
Source

pub fn set_jira_url(&mut self, jira_url: String)

Set the Jira URL for the ConfigFile struct. This is the base URL for the Jira API.

§Arguments
  • jira_url - The base URL for the Jira API.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.set_jira_url("jira_url".to_string());

assert_eq!(config.get_jira_url(), "jira_url");
Source

pub fn get_jira_url(&self) -> &str

Get the Jira URL for the ConfigFile struct. This is the base URL for the Jira API.

§Returns
  • The base URL for the Jira API.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());
let jira_url = config.get_jira_url();

assert_eq!(jira_url, "jira_url");
Source

pub fn set_standard_resolution(&mut self, standard_resolution: String)

Set the standard resolution for the ConfigFile struct. This is the standard resolution that will be used when resolving an issue.

§Arguments
  • standard_resolution - The standard resolution to be used when resolving an issue.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.set_standard_resolution("standard_resolution".to_string());

assert_eq!(config.get_standard_resolution(), "standard_resolution");
Source

pub fn get_standard_resolution(&self) -> &String

Get the standard resolution for the ConfigFile struct. This is the standard resolution that will be used when resolving an issue.

§Returns
  • The standard resolution to be used when resolving an issue.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());
let standard_resolution = config.get_standard_resolution();

assert_eq!(config.get_standard_resolution(), "standard_resolution");
Source

pub fn set_standard_resolution_comment( &mut self, standard_resolution_comment: String, )

Set the standard resolution comment for the ConfigFile struct. This is the standard resolution comment that will be used when resolving an issue.

§Arguments
  • standard_resolution_comment - The standard resolution comment to be used when resolving an issue.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.set_standard_resolution_comment("standard_resolution_comment".to_string());

assert_eq!(config.get_standard_resolution_comment(), "standard_resolution_comment");
Source

pub fn get_standard_resolution_comment(&self) -> &String

Get the standard resolution comment for the ConfigFile struct. This is the standard resolution comment that will be used when resolving an issue.

§Returns
  • The standard resolution comment to be used when resolving an issue.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());
let standard_resolution_comment = config.get_standard_resolution_comment();

assert_eq!(standard_resolution_comment, "standard_resolution_comment");
Source

pub fn add_transition_name(&mut self, key: String, value: String)

Add a transition name to the ConfigFile struct. This is used to store the transition name for a specific transition. This is used to transition an issue to a specific state. The key is the transition internal identifier and the value is the transition name.

§Arguments
  • key - The transition internal identifier.
  • value - The transition name.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.add_transition_name("transition_key".to_string(), "Transition name".to_string());

assert_eq!(config.get_transition_name("transition_key"), Some(vec!["Transition name".to_string()]));
Source

pub fn get_transition_name(&self, key: &str) -> Option<Vec<String>>

Get the transition name for a specific transition internal identifier. This is used to transition an issue to a specific state. The key is the transition internal identifier and the value is the transition name. If the transition internal identifier does not exist, None is returned.

§Arguments
  • key - The transition internal identifier.
§Returns
  • The transition name for the specific transition internal identifier.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let mut config = ConfigFile::default();
config.add_transition_name("transition_key".to_string(), "Transition name".to_string());

assert_eq!(config.get_transition_name("transition_key"), Some(vec!["Transition name".to_string()]));
Source

pub fn write_to_file(&self, file_path: &str) -> Result<(), Error>

Stores the configuration to a file. This will overwrite the file if it already exists.

§Arguments
  • file_path - The path to the file to write the configuration to.
§Returns
  • A Result containing either an empty Ok or an error.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::new("auth_token".to_string(), "jira_url".to_string(), "standard_resolution".to_string(), "standard_resolution_comment".to_string(), Table::new());
let result = config.write_to_file("config.toml");

assert!(result.is_ok());
Source

pub fn read_from_file(file_path: &str) -> Result<ConfigFile, Error>

Loads the configuration from a file. If the file does not exist, it will return a ConfigFile with default values. If the file is not valid toml, it will return an error. If the file is valid toml, it will return the ConfigFile.

§Arguments
  • file_path - The path to the file to read the configuration from.
§Returns
  • A Result containing either the ConfigFile or an error.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use std::path::Path;

// Try both possible paths to handle different working directories
let config_path = if Path::new("config_example.toml").exists() {
    "config_example.toml"
} else {
    "jirust-cli/config_example.toml"
};

let config = ConfigFile::read_from_file(config_path);

assert!(config.clone().is_ok());
assert_eq!(config.clone().unwrap().get_auth_key(), "auth_key");
assert_eq!(config.clone().unwrap().get_jira_url(), "jira_url");

Trait Implementations§

Source§

impl Clone for ConfigFile

Source§

fn clone(&self) -> ConfigFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ConfigFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ConfigFile

Source§

fn default() -> ConfigFile

Create a new ConfigFile struct with default values. This is useful for creating a new configuration file. The default values can be set using the set methods. The default values are:

  • auth_token: “”
  • jira_url: “”
  • standard_resolution: “”
  • standard_resolution_comment: “”
  • transitions_names: Table::new()
§Returns
  • A new ConfigFile struct with default values.
§Examples
use jirust_cli::config::config_file::ConfigFile;
use toml::Table;

let config = ConfigFile::default();

assert_eq!(config.get_auth_key(), "");
assert_eq!(config.get_jira_url(), "");
assert_eq!(config.get_standard_resolution(), "");
assert_eq!(config.get_standard_resolution_comment(), "");
Source§

impl<'de> Deserialize<'de> for ConfigFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ConfigFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,