### Example: Using Sprinkles to List Installed Apps (Rust) Source: https://github.com/winpax/sprinkles/blob/trunk/README.md This snippet demonstrates how to use the Sprinkles library in Rust to get a list of installed applications via Scoop. It requires the 'sprinkles' crate and utilizes the User context for interacting with the Scoop environment. The output is the count of installed applications. ```rust use sprinkles::contexts::{User, ScoopContext}; let ctx = User::new().unwrap(); let apps = ctx.installed_apps().unwrap(); println!("You have {} apps installed", apps.len()); ``` -------------------------------- ### List Installed Scoop Applications in Rust Source: https://context7.com/winpax/sprinkles/llms.txt Shows how to retrieve and list all installed Scoop applications using the `sprinkles` library. It demonstrates fetching install manifests, their versions, and checking for the installation status of specific applications. Dependencies include `sprinkles` and its `contexts` and `packages` modules. ```rust use sprinkles::contexts::{ScoopContext, User}; use sprinkles::packages::{CreateManifest, InstallManifest, Manifest}; fn main() -> Result<(), Box> { let ctx = User::new()?; // Get paths to all installed apps let app_paths = ctx.installed_apps()?; println!("Found {} installed apps", app_paths.len()); // List all install manifests with error handling let install_manifests = InstallManifest::list_all(&ctx)?; for manifest in &install_manifests { println!("Installed: {} (version: {})", unsafe { manifest.name() }, manifest.version ); } // List all app manifests (ignoring errors) let manifests = InstallManifest::list_all_unchecked(&ctx)?; for manifest in manifests { println!("App: {}", unsafe { manifest.name() }); } // Check if specific app is installed if ctx.app_installed("git")? { println!("Git is installed"); } Ok(()) } ``` -------------------------------- ### Manage Install Manifests with Rust Source: https://context7.com/winpax/sprinkles/llms.txt This snippet shows how to work with install manifests using the Sprinkles library in Rust. It covers loading an install manifest from a file path, accessing its properties, retrieving the source bucket, listing all installed packages, and obtaining install information from a regular manifest. This functionality relies on the 'sprinkles' crate. ```rust use sprinkles::contexts::{ScoopContext, User}; use sprinkles::packages::{CreateManifest, InstallManifest, Manifest}; use std::path::Path; fn main() -> Result<(), Box> { let ctx = User::new()?; // Load install manifest from path let install_path = ctx.apps_path().join("git/current/install.json"); let install_manifest = InstallManifest::from_path(install_path)?; // Access install manifest properties println!("Installed package: {}", unsafe { install_manifest.name() }); println!("Version: {}", install_manifest.version); if let Some(bucket) = &install_manifest.bucket { println!("Source bucket: {}", bucket); } println!("Architecture: {}", install_manifest.architecture); // Get source bucket name let source = install_manifest.get_source(); println!("Installed from: {}", source); // List all install manifests let all_installs = InstallManifest::list_all(&ctx)?; println!("Total installed packages: {}", all_installs.len()); for install in all_installs { println!(" {} v{} from ", unsafe { install.name() }, install.version, install.get_source() ); } // Get install manifest from regular manifest let manifest = Manifest::from_reference(&ctx, ("main".to_string(), "git".to_string()))?; if let Ok(install_info) = manifest.install_manifest(&ctx) { println!("Git install info: version {}", install_info.version); } Ok(()) } ``` -------------------------------- ### Generate Benchmark File (Windows) Source: https://github.com/winpax/sprinkles/blob/trunk/README.md This command generates a large binary file (`large-file.bin`) with random data, suitable for benchmarking disk I/O operations. It requires the `genfile` tool to be installed on Windows. ```powershell genfile --size 512mb -o benches/large-file.bin --random ``` -------------------------------- ### Load and Parse Manifests from Files, Buckets, and Strings Source: https://context7.com/winpax/sprinkles/llms.txt Demonstrates loading package manifests using the Sprinkles library from local file paths, remote buckets, or directly from JSON strings. It also shows how to access common manifest properties like name, version, description, homepage, and dependencies. Dependencies include the 'sprinkles' crate and its submodules for packages and contexts. Outputs include parsed manifest data and whether a package is installed. ```rust use sprinkles::packages::{CreateManifest, Manifest}; use sprinkles::contexts::{ScoopContext, User}; use sprinkles::Architecture; use std::path::Path; fn main() -> Result<(), Box> { let ctx = User::new()?; // Load manifest from file path let manifest_path = Path::new("path/to/manifest.json"); let manifest = Manifest::from_path(manifest_path)?; // Load manifest from string let json_str = r#"{"version": "1.0", "url": "https://example.com/app.zip"}"#; let manifest = Manifest::from_str(json_str)?; // Load manifest from bucket and name let manifest = Manifest::from_reference(&ctx, ("main".to_string(), "git".to_string()))?; // Access manifest properties println!("Package: {}", unsafe { manifest.name() }); println!("Version: {}", manifest.version); println!("Description: {}", manifest.description.unwrap_or_default()); println!("Homepage: {}", manifest.homepage.unwrap_or_default()); // Get architecture-specific install config let install_config = manifest.install_config(Architecture::X64); // Get download URLs for current architecture if let Some(urls) = manifest.download_urls(Architecture::ARCH) { for url in urls { println!("Download URL: {}", url.url); } } // List dependencies let deps = manifest.depends(); for dep in deps { println!("Depends on: {:?}", dep); } // Check if manifest is installed if manifest.is_installed(&ctx, Some("main")) { println!("Package is installed from main bucket"); } Ok(()) } ``` -------------------------------- ### Handle Multi-Architecture Package Operations Source: https://context7.com/winpax/sprinkles/llms.txt This code demonstrates how to work with package configurations and downloads specific to different architectures (e.g., x64, x86, arm64). It shows how to retrieve architecture-specific download URLs, install configurations, and autoupdate settings using the Sprinkles library. Dependencies include 'sprinkles' crate and its Architecture enum. Outputs include information about URLs, filenames, binaries, and autoupdate configurations for various architectures. ```rust use sprinkles::Architecture; use sprinkles::packages::{CreateManifest, Manifest}; use sprinkles::contexts::{ScoopContext, User}; fn main() -> Result<(), Box> { let ctx = User::new()?; // Get current system architecture let current_arch = Architecture::from_env(); println!("Current architecture: {}", current_arch); // Work with all supported architectures let architectures = [Architecture::X64, Architecture::X86, Architecture::Arm64]; let manifest = Manifest::from_reference(&ctx, ("main".to_string(), "python".to_string()))?; for arch in architectures { println!("\nArchitecture: {}", arch); // Get architecture-specific download URLs if let Some(urls) = manifest.download_urls(arch) { for url in urls { println!(" URL: {}", url.url); if let Some(filename) = url.filename { println!(" Filename: {}", filename); } } } // Get architecture-specific install configuration let config = manifest.install_config(arch); if let Some(bin) = config.bin { println!(" Binaries: {:?}", bin); } // Get autoupdate config for architecture if let Some(autoupdate) = manifest.autoupdate_config(arch) { if let Some(update_url) = autoupdate.url { println!(" Autoupdate URL: {:?}", update_url); } } } // Parse architecture from string let arch = Architecture::from_scoop_string("64bit"); assert_eq!(arch, Architecture::X64); Ok(()) } ``` -------------------------------- ### Initialize Scoop User Context in Rust Source: https://context7.com/winpax/sprinkles/llms.txt Demonstrates how to initialize a user-specific Scoop context using `sprinkles::contexts::User::new()`. This context provides access to Scoop's installation paths and allows checking for updates. It requires the `sprinkles` crate. ```rust use sprinkles::contexts::{ScoopContext, User}; fn main() -> Result<(), Box> { // Create a new user context let ctx = User::new()?; // Access various Scoop paths let scoop_path = ctx.path(); let apps_path = ctx.apps_path(); let buckets_path = ctx.buckets_path(); let cache_path = ctx.cache_path(); println!("Scoop installed at: {}", scoop_path.display()); println!("Apps directory: {}", apps_path.display()); println!("Buckets directory: {}", buckets_path.display()); // Check if context is outdated let is_outdated = ctx.outdated().await?; if is_outdated { println!("Scoop installation is outdated"); } Ok(()) } ``` -------------------------------- ### Manage Scoop Buckets in Rust Source: https://context7.com/winpax/sprinkles/llms.txt Provides examples of managing Scoop buckets (package repositories) using the `sprinkles` Rust library. It covers listing buckets, retrieving their paths and manifest counts, checking for outdated status, and accessing specific package manifests. Requires the `sprinkles` crate, specifically the `buckets` and `contexts` modules. ```rust use sprinkles::buckets::Bucket; use sprinkles::contexts::{ScoopContext, User}; fn main() -> Result<(), Box> { let ctx = User::new()?; // List all available buckets let buckets = Bucket::list_all(&ctx)?; for bucket in &buckets { println!("Bucket: {}", bucket.name()); println!(" Path: {}", bucket.path().display()); println!(" Manifests: {}", bucket.manifests()?); // Get bucket source URL if let Ok(source) = bucket.source() { println!(" Source: {}", source); } // Check if bucket is outdated if bucket.outdated()? { println!(" Status: Outdated"); } } // Open a specific bucket by name let main_bucket = Bucket::from_name(&ctx, "main")?; // List all packages in the bucket let packages = main_bucket.list_packages()?; println!("Main bucket has {} packages", packages.len()); // List package names only let package_names = main_bucket.list_package_names()?; for name in package_names.iter().take(5) { println!(" - {}", name); } // Get a specific manifest from a bucket let manifest = main_bucket.get_manifest("git")?; println!("Git manifest: version {}", manifest.version); Ok(()) } ``` -------------------------------- ### Search Packages Using Regex and Search Modes Source: https://context7.com/winpax/sprinkles/llms.txt This snippet shows how to search for packages within a specific bucket using regular expressions. It supports searching by package name, binary names, or both, and can filter results to include only installed packages. Key dependencies include the 'sprinkles' crate, 'regex' crate, and context modules. The output is a list of matching package manifests. ```rust use sprinkles::buckets::Bucket; use sprinkles::contexts::{ScoopContext, User}; use sprinkles::packages::SearchMode; use regex::Regex; fn main() -> Result<(), Box> { let ctx = User::new()?; // Search by package name let search_regex = Regex::new("^git")?; let main_bucket = Bucket::from_name(&ctx, "main")?; // Search only package names let matches = main_bucket.matches( &ctx, false, // not installed_only &search_regex, SearchMode::Name )?; println!("Packages matching 'git':"); for manifest in matches { println!(" - {} ({})", unsafe { manifest.name() }, manifest.version); } // Search only in binaries let binary_search = Regex::new("python")?; let binary_matches = main_bucket.matches( &ctx, false, &binary_search, SearchMode::Binary )?; // Search both names and binaries let both_matches = main_bucket.matches( &ctx, false, &search_regex, SearchMode::Both )?; // Search only installed packages let installed_matches = main_bucket.matches( &ctx, true, // installed_only &search_regex, SearchMode::Name )?; println!("Installed packages matching 'git': {}", installed_matches.len()); Ok(()) } ``` -------------------------------- ### Generate Benchmark File (Linux) Source: https://github.com/winpax/sprinkles/blob/trunk/README.md This command generates a large binary file (`large-file.bin`) with random data using `/dev/urandom` on Linux systems. This file is intended for benchmarking disk I/O performance. ```bash dd if=/dev/urandom of=benches/large-file.bin bs=1M count=512 ``` -------------------------------- ### Interact with Git Repositories using Rust Source: https://context7.com/winpax/sprinkles/llms.txt This snippet demonstrates how to interact with Git repositories using the Sprinkles library in Rust. It covers opening a bucket as a Git repository, checking the current branch, updating the repository, retrieving the origin URL, and accessing last updated information for a manifest. It requires the 'sprinkles' crate. ```rust use sprinkles::buckets::Bucket; use sprinkles::contexts::{ScoopContext, User}; use sprinkles::git::Repo; use sprinkles::packages::{CreateManifest, Manifest}; fn main() -> Result<(), Box> { let ctx = User::new()?; // Open bucket as Git repository let bucket = Bucket::from_name(&ctx, "main")?; let repo = bucket.open_repo()?; // Get current branch let branch = repo.current_branch()?; println!("Current branch: {}", branch); // Check if repository is outdated if repo.outdated()? { println!("Repository needs updating"); // Pull latest changes repo.pull(&ctx, None)?; } // Get repository origin URL if let Some(origin) = repo.origin() { if let Some(url) = origin.url(gix::remote::Direction::Fetch) { println!("Origin URL: {}", url); } } // Open Scoop app repository if let Some(scoop_repo_result) = ctx.open_repo() { let scoop_repo = scoop_repo_result?; println!("Scoop app repo: {}", scoop_repo.path().display()); } // Get last update info for a manifest let manifest = Manifest::from_reference(&ctx, ("main".to_string(), "git".to_string()))?; if let Ok((datetime, signature)) = manifest.last_updated_info(&ctx) { if let Some(dt) = datetime { println!("Last updated: {}", dt); } if let Some(sig) = signature { println!("Author: {} <{}>", sig.name, sig.email); } } Ok(()) } ``` -------------------------------- ### Rust: Manage Manifest Autoupdate and Version Source: https://context7.com/winpax/sprinkles/llms.txt This Rust code snippet demonstrates how to load a manifest, retrieve its autoupdate configuration (including URL and hash details), update the manifest to a new version, and check for the presence of autoupdate fields. It utilizes the `sprinkles` crate and requires the `manifest-hashes` feature for version updates and hash calculation. ```rust use sprinkles::contexts::{ScoopContext, User}; use sprinkles::packages::{CreateManifest, Manifest}; use sprinkles::Architecture; #[tokio::main] async fn main() -> Result<(), Box> { let ctx = User::new()?; // Load a manifest with autoupdate config let mut manifest = Manifest::from_reference(&ctx, ("main".to_string(), "git".to_string()))?; println!("Current version: {}", manifest.version); // Get autoupdate configuration if let Some(autoupdate_config) = manifest.autoupdate_config(Architecture::ARCH) { println!("Autoupdate enabled"); if let Some(url) = autoupdate_config.url { println!("Update URL pattern: {:?}", url); } if let Some(hash_config) = autoupdate_config.hash { println!("Hash extraction configured: {:?}", hash_config); } } // Update manifest to new version (requires manifest-hashes feature) #[cfg(feature = "manifest-hashes")] { let new_version = "2.45.0".to_string(); manifest.set_version(&ctx, new_version).await?; println!("Updated to version: {}", manifest.version); // New download URLs and hashes are automatically calculated if let Some(urls) = manifest.download_urls(Architecture::ARCH) { for url in urls { println!("New URL: {}", url.url); } } } // Check if manifest has autoupdate field if manifest.autoupdate.is_some() { println!("Autoupdate configuration available"); } Ok(()) } ``` -------------------------------- ### Rust: Query Bucket Usage and Statistics Source: https://context7.com/winpax/sprinkles/llms.txt This Rust code snippet shows how to interact with Scoop buckets using the `sprinkles` crate. It covers fetching all used buckets, checking if a specific bucket is in use, retrieving statistics for all buckets (including package count, usage status, and outdated status), and loading specific or all buckets. ```rust use sprinkles::buckets::Bucket; use sprinkles::contexts::{ScoopContext, User}; fn main() -> Result<(), Box> { let ctx = User::new()?; // Get all used buckets (buckets with installed packages) let used_buckets = Bucket::used(&ctx)?; println!("Buckets in use:"); for bucket_name in &used_buckets { println!(" - {}", bucket_name); } // Check if specific bucket is used let main_bucket = Bucket::from_name(&ctx, "main")?; if main_bucket.is_used(&ctx)? { println!("Main bucket has installed packages"); } // Get statistics for all buckets let all_buckets = Bucket::list_all(&ctx)?; for bucket in all_buckets { let name = bucket.name(); let manifest_count = bucket.manifests()?; let is_used = bucket.is_used(&ctx)?; let is_outdated = bucket.outdated()?; println!("\nBucket: {}", name); println!(" Packages: {}", manifest_count); println!(" In use: {}", is_used); println!(" Outdated: {}", is_outdated); // Get source URL if let Ok(source_url) = bucket.source() { println!(" URL: {}", source_url); } } // Load one bucket or all buckets let buckets = Bucket::one_or_all(&ctx, Some("main"))?; println!("Loaded {} bucket(s)", buckets.len()); let all = Bucket::one_or_all(&ctx, None::)?; println!("All buckets: {}", all.len()); Ok(()) } ``` -------------------------------- ### Manage Scoop Configuration with Rust Source: https://context7.com/winpax/sprinkles/llms.txt This snippet demonstrates how to manage Scoop configuration settings using the Sprinkles library in Rust. It covers accessing configuration details like Scoop branch, symlink status, proxy settings, and cache paths. It also shows how to modify configuration and load the Scoop configuration directly. The 'sprinkles' crate is a prerequisite. ```rust use sprinkles::contexts::{ScoopContext, User}; use sprinkles::config::Scoop; fn main() -> Result<(), Box> { let mut ctx = User::new()?; // Access configuration let config = ctx.config(); println!("Scoop branch: {:?}", config.scoop_branch); // Check symlink settings if ctx.symlinks_enabled() { println!("Symlinks are enabled"); } // Access proxy settings if let Some(proxy) = ctx.proxy() { println!("Using proxy: {:?}", proxy); } // Get cache path from config let cache_path = ctx.cache_path(); println!("Cache directory: {}", cache_path.display()); // Modify configuration let config_mut = ctx.config_mut(); // Make changes to config as needed // Load config directly let scoop_config = Scoop::load()?; println!("Root path: {}", scoop_config.root_path.display()); if let Some(global_path) = scoop_config.global_path { println!("Global path: {}", global_path.display()); } Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.