workspace_basic_usage/
workspace_basic_usage.rs1use workspace_tools::{ workspace, WorkspaceError };
6
7fn main() -> Result< (), WorkspaceError >
8{
9 if std::env::var( "WORKSPACE_PATH" ).is_err()
11 {
12 println!( "setting WORKSPACE_PATH to current directory for demo" );
13 std::env::set_var( "WORKSPACE_PATH", std::env::current_dir().unwrap() );
14 }
15
16 println!( "resolving workspace..." );
18 let ws = workspace()?;
19
20 println!( "workspace root: {}", ws.root().display() );
21
22 println!( "\nstandard directories:" );
24 println!( " config: {}", ws.config_dir().display() );
25 println!( " data: {}", ws.data_dir().display() );
26 println!( " logs: {}", ws.logs_dir().display() );
27 println!( " docs: {}", ws.docs_dir().display() );
28 println!( " tests: {}", ws.tests_dir().display() );
29
30 println!( "\npath joining examples:" );
32 let app_config = ws.join( "config/app.toml" );
33 let cache_file = ws.join( "data/cache.db" );
34 let log_file = ws.join( "logs/application.log" );
35
36 println!( " app config: {}", app_config.display() );
37 println!( " cache file: {}", cache_file.display() );
38 println!( " log file: {}", log_file.display() );
39
40 println!( "\nworkspace boundary checking:" );
42 println!( " app_config in workspace: {}", ws.is_workspace_file( &app_config ) );
43 println!( " /etc/passwd in workspace: {}", ws.is_workspace_file( "/etc/passwd" ) );
44
45 println!( "\nvalidating workspace..." );
47 match ws.validate()
48 {
49 Ok( () ) => println!( " workspace structure is valid" ),
50 Err( e ) => println!( " workspace validation failed: {e}" ),
51 }
52
53 Ok( () )
54}