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
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 fileread_from_file(file: &str) -> Result<ConfigFile, std::io::Error>- reads the ConfigFile from a fileget_auth() -> AuthSection- gets the AuthSection from the ConfigFileget_jira() -> JiraSection- gets the JiraSection from the ConfigFileset_auth(auth: AuthSection)- sets the AuthSection in the ConfigFileset_jira(jira: JiraSection)- sets the JiraSection in the ConfigFile
sourcepub fn new(auth_token: String, jira_url: String) -> ConfigFile
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");sourcepub fn default() -> ConfigFile
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(), "");sourcepub fn set_auth_key(&mut self, auth_token: String)
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");sourcepub fn get_auth_key(&self) -> &str
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");sourcepub fn set_jira_url(&mut self, jira_url: String)
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");sourcepub fn get_jira_url(&self) -> &str
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");sourcepub fn write_to_file(&self, file_path: &str) -> Result<(), Error>
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());sourcepub fn read_from_file(file_path: &str) -> Result<ConfigFile, Error>
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
impl Clone for ConfigFile
source§fn clone(&self) -> ConfigFile
fn clone(&self) -> ConfigFile
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ConfigFile
impl Debug for ConfigFile
source§impl<'de> Deserialize<'de> for ConfigFile
impl<'de> Deserialize<'de> for ConfigFile
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ConfigFile
impl RefUnwindSafe for ConfigFile
impl Send for ConfigFile
impl Sync for ConfigFile
impl Unpin for ConfigFile
impl UnwindSafe for ConfigFile
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)