1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Utility functions for bbcache configuration and display.
//!
//! This module provides helper functions for:
//! - Determining default cache locations and API endpoints
//! - Formatting and displaying cached resources in tabular form
use ;
use Resource;
use home_dir;
use env;
use PathBuf;
use ;
/// Printable representation of a cached resource for display in tables.
///
/// This struct is used internally by [`print_resources`] to format resource
/// information in a human-readable tabular format.
/// Returns the default cache folder path.
///
/// The cache folder is determined in the following priority order:
/// 1. `BBCLIENT_CACHE` environment variable if set
/// 2. `$HOME/.bbcache/` if home directory is available
/// 3. `/tmp/.bbcache/` as a fallback
///
/// # Returns
///
/// A [`PathBuf`] pointing to the cache folder location.
///
/// # Examples
///
/// ```rust
/// use gtars_bbcache::utils::get_default_cache_folder;
///
/// let cache_path = get_default_cache_folder();
/// println!("Cache will be stored at: {:?}", cache_path);
/// ```
///
/// # Environment Variables
///
/// - `BBCLIENT_CACHE`: Custom cache directory path (highest priority)
/// - `HOME`: User's home directory (used for default location)
/// Returns the default BEDbase API endpoint URL.
///
/// The API endpoint is determined in the following priority order:
/// 1. `BEDBASE_API` environment variable if set
/// 2. `https://api.bedbase.org` as the default
///
/// # Returns
///
/// A [`String`] containing the BEDbase API endpoint URL.
///
/// # Examples
///
/// ```rust
/// use gtars_bbcache::utils::get_default_bedbase_api;
///
/// let api_url = get_default_bedbase_api();
/// println!("Using BEDbase API at: {}", api_url);
/// ```
///
/// # Environment Variables
///
/// - `BEDBASE_API`: Custom BEDbase API endpoint
/// Prints a list of resources in a formatted table.
///
/// This function takes a vector of [`Resource`] objects and displays them
/// in a tabular format showing identifiers and paths. Useful for displaying
/// the results of [`BBClient::list_beds`] or [`BBClient::list_bedsets`].
///
/// # Arguments
///
/// * `resources` - Vector of resources to display
///
/// # Examples
///
/// ```rust,no_run
/// use gtars_bbcache::client::BBClient;
/// use gtars_bbcache::utils::print_resources;
///
/// # fn main() -> anyhow::Result<()> {
/// let mut client = BBClient::builder().finish()?;
/// let beds = client.list_beds()?;
/// print_resources(beds);
/// # Ok(())
/// # }
/// ```
///
/// # Output Format
///
/// ```text
/// ┌────────────────────────────────┬─────────────────────────┐
/// │ id │ path │
/// ├────────────────────────────────┼─────────────────────────┤
/// │ 6b2e163a1d4319d99bd465c6c78... │ /path/to/cache/6/b/... │
/// └────────────────────────────────┴─────────────────────────┘
/// ```