Struct jirust_cli::config::config_file::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
source

pub fn new(auth_token: String, jira_url: String) -> 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.
§Returns
  • A new ConfigFile struct.
§Examples
use jirust_cli::config::config_file::ConfigFile;

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

assert_eq!(config.get_auth_key(), "auth_token");
assert_eq!(config.get_jira_url(), "jira_url");
source

pub 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: “”
§Returns
  • A new ConfigFile struct with default values.
§Examples
use jirust_cli::config::config_file::ConfigFile;

let config = ConfigFile::default();

assert_eq!(config.get_auth_key(), "");
assert_eq!(config.get_jira_url(), "");
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;

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

assert_eq!(auth_key, "auth_key");
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;

let config = ConfigFile::new("auth_key".to_string(), "jira_url".to_string());
let jira_url = config.get_jira_url();

assert_eq!(jira_url, "jira_url");
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;

let config = ConfigFile::new("auth_key".to_string(), "jira_url".to_string());
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;

let config = ConfigFile::read_from_file("config_example.toml");

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 copy 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<'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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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>,