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
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 ConfigFileset_standard_resolution(standard_resolution: String)- sets the standard_resolution in the ConfigFileget_standard_resolution() -> String- gets the standard_resolution from the ConfigFileset_standard_resolution_comment(standard_resolution_comment: String)- sets the standard_resolution_comment in the ConfigFileget_standard_resolution_comment() -> String- gets the standard_resolution_comment from the Configadd_transition_name(key: String, value: String)- adds a transition_name to the ConfigFileget_transition_name(key: &str) -> Option<String>- gets a transition_name from the ConfigFile
Sourcepub fn new(
auth_token: String,
jira_url: String,
standard_resolution: String,
standard_resolution_comment: String,
transitions_names: Table,
) -> ConfigFile
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");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;
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");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;
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");Sourcepub fn set_standard_resolution(&mut self, standard_resolution: String)
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");Sourcepub fn get_standard_resolution(&self) -> &String
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");Sourcepub fn set_standard_resolution_comment(
&mut self,
standard_resolution_comment: String,
)
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");Sourcepub fn get_standard_resolution_comment(&self) -> &String
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");Sourcepub fn add_transition_name(&mut self, key: String, value: String)
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()]));Sourcepub fn get_transition_name(&self, key: &str) -> Option<Vec<String>>
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()]));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;
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());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;
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
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 Default for ConfigFile
impl Default for ConfigFile
Source§fn default() -> ConfigFile
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(), "");