Expand description
§Common utilities
This module contains common functions and data structures used to build the ACORN command line interface as well as support open science endeavors.
§Example Uses
§Work with semantic versions
ⓘ
use acorn_lib::util::SemanticVersion;
let version = SemanticVersion::from_string("1.2.3");
assert_eq!(version.minor, 2);
if let Some(version) = SemanticVersion::from_command("cargo") {
println!("cargo version: {version}");
}§Perform file read and write operations
ⓘ
use acorn_lib::util::{checksum, read_file, write_file};
use std::path::PathBuf;
// Verify file integrity
assert_eq!(checksum(PathBuf::from("/path/to/file")), "somesha256hashvaluethatisreallylong");
// Read file contents
let contents = read_file(PathBuf::from("/path/to/this/file"));
// Write file contents
write_file(PathBuf::from("/path/to/that/file"), contents);Modules§
Structs§
- Constant
- Struct for using and sharing constants
- Gitlab
Merge Request Diff Response - Struct for parsing GitLab API merge request diff responses
- Label
- Struct for using and sharing colorized logging labels
- Semantic
Version - Semantic version
- Semantic
Version Builder - Use builder syntax to set the inputs and finish with
build(). - String
List - Struct for adding ToStringList functionality
Enums§
Traits§
- ToAbsolute
String - Trait for augmenting path value functionality with absolute path string conversion
- ToString
Chunks - Trait for adding chunking functionality
- ToStrings
- Trait for converting a vector of PathBufs to a vector of strings
Functions§
- checksum
- Get SHA256 hash of a file
- command_
exists - Checks if a given command exists in current terminal context.
- download_
binary - Downloads a binary file from the given URL to the destination path.
- extension
- Get file extension
- extract_
zip - Extract zip archive
- files_
all - Returns a vector of
PathBufcontaining all files in a directory that match at least one of the given extensions. - files_
from_ git_ branch - Returns a vector of
PathBufcontaining all files changed in the given Git branch relative to the default branch. - files_
from_ git_ commit - Returns a vector of
PathBufcontaining all files changed in the given Git commit. - files_
from_ gitlab_ merge_ request - Returns a vector of
PathBufcontaining all files changed in a GitLab merge request, as determined by theCI_API_V4_URL,CI_MERGE_REQUEST_PROJECT_ID, andCI_MERGE_REQUEST_IIDenvironment variables. - filter_
ignored - Return file paths in a vector that don’t match the ignore pattern
- find_
first - Return fisrt key/value pair with key that matches pattern
- generate_
guid - Generates a random GUID using a custom alphabet.
- git_
branch_ name - Returns the current Git branch name if the
gitcommand is available and executed successfully. - git_
default_ branch_ name - Returns the default Git branch name if the
gitcommand is available and executed successfully. - image_
paths - Returns a vector of
PathBufrepresenting paths to all images found in the given directory and all of its subdirectories. - make_
executable - Makes the given file executable.
- parent
- Returns the absolute path of the parent directory for the given path.
- print_
changes - Prints a diff of changes between two strings.
- print_
values_ as_ table - Prints the given values as a table.
- read_
file - Reads the given file and returns its contents as a string.
- regex_
capture_ lookup - Helper function to create a lookup dictionary for regex captures
- reqwest_
request - Utility method to employ best practices when using a Reqwest client to make HTTP requests.
- snake_
case - Converts the given string to snake case.
- standard_
project_ folder - Returns path to a folder in the operating system’s cache directory that is unique to the given
namespacewith a random UUID as the name of the final folder. - suffix
- Returns “s” if the given value is not 1, otherwise returns an empty string.
- text_
diff_ changes - Computes the differences between two strings line by line and returns a vector of changes.
- to_
absolute_ string - Converts a
PathBufinto aStringrepresentation of the absolute path. - to_
string - Convert a vector of string slices to a vector of strings
- tokio_
runtime - Create a new Tokio runtime
- write_
file - Writes the given content to a file at the given path.