pub fn workspace() -> Result<Workspace>
Expand description
Examples found in repository?
examples/008_web_service_integration.rs (line 75)
65 fn new() -> Result< Self, Box< dyn core::error::Error > >
66 {
67 println!( "1️⃣ initializing web service..." );
68
69 // setup workspace
70 if std::env::var( "WORKSPACE_PATH" ).is_err()
71 {
72 std::env::set_var( "WORKSPACE_PATH", std::env::current_dir()? );
73 }
74
75 let workspace = workspace()?;
76
77 // create web service directory structure
78 Self::setup_web_structure( &workspace )?;
79
80 // load configuration
81 let config = Self::load_config( &workspace )?;
82
83 println!( " ✅ web service initialized" );
84
85 Ok( Self { workspace, config } )
86 }
More examples
examples/007_real_world_cli_app.rs (line 77)
67 fn new() -> Result< Self, Box< dyn core::error::Error > >
68 {
69 println!( "1️⃣ initializing cli application..." );
70
71 // setup workspace
72 if std::env::var( "WORKSPACE_PATH" ).is_err()
73 {
74 std::env::set_var( "WORKSPACE_PATH", std::env::current_dir()? );
75 }
76
77 let workspace = workspace()?;
78
79 // ensure directory structure exists
80 Self::ensure_directory_structure( &workspace )?;
81
82 // load configuration
83 let config = Self::load_configuration( &workspace )?;
84
85 // setup logging
86 Self::setup_logging( &workspace, &config )?;
87
88 println!( " ✅ application initialized successfully" );
89
90 Ok( Self { workspace, config } )
91 }
examples/009_advanced_patterns.rs (line 74)
65 fn new() -> Result< Self, Box< dyn core::error::Error > >
66 {
67 println!( "1️⃣ initializing advanced workspace manager..." );
68
69 if std::env::var( "WORKSPACE_PATH" ).is_err()
70 {
71 std::env::set_var( "WORKSPACE_PATH", std::env::current_dir()? );
72 }
73
74 let workspace = workspace()?;
75
76 // initialize plugin system
77 let mut plugins = Self::create_plugins();
78 for plugin in &mut plugins
79 {
80 plugin.initialize( &workspace )?;
81 println!( " initialized plugin: {}", plugin.name() );
82 }
83
84 // setup environments
85 let environments = Self::create_environments();
86
87 // create advanced directory structure
88 Self::setup_advanced_structure( &workspace )?;
89
90 println!( " ✅ advanced manager initialized with {} plugins", plugins.len() );
91
92 Ok( Self { workspace, plugins, environments } )
93 }
examples/000_hello_workspace.rs (line 21)
8fn main() -> Result< (), WorkspaceError >
9{
10 // workspace_tools works by reading the WORKSPACE_PATH environment variable
11 // if it's not set, we'll set it to current directory for this demo
12 if std::env::var( "WORKSPACE_PATH" ).is_err()
13 {
14 let current_dir = std::env::current_dir().unwrap();
15 std::env::set_var( "WORKSPACE_PATH", ¤t_dir );
16 println!( "📍 set WORKSPACE_PATH to: {}", current_dir.display() );
17 }
18
19 // the fundamental operation: get a workspace instance
20 println!( "🔍 resolving workspace..." );
21 let ws = workspace()?;
22
23 // every workspace has a root directory
24 println!( "✅ workspace root: {}", ws.root().display() );
25
26 // that's it! you now have reliable, workspace-relative path resolution
27 // no more brittle "../../../config/file.toml" paths
28
29 println!( "\n🎉 workspace resolution successful!" );
30 println!( "next: run example 001 to learn about standard directories" );
31
32 Ok( () )
33}
examples/006_improved_secrets_api.rs (line 20)
10fn main() -> Result< (), workspace_tools::WorkspaceError >
11{
12 println!( "🔒 Enhanced Secrets API - Task 021 Demo\n" );
13
14 // Setup workspace
15 if std::env::var( "WORKSPACE_PATH" ).is_err()
16 {
17 std::env::set_var( "WORKSPACE_PATH", std::env::current_dir().unwrap() );
18 }
19
20 let ws = workspace_tools::workspace()?;
21
22 // 1. Enhanced error handling demonstration
23 println!( "1️⃣ Enhanced Error Handling:" );
24 demonstrate_enhanced_errors( &ws )?;
25
26 // 2. Path-aware methods demonstration
27 println!( "\n2️⃣ Path-aware Methods:" );
28 demonstrate_path_methods( &ws )?;
29
30 // 3. Helper methods demonstration
31 println!( "\n3️⃣ Helper Methods:" );
32 demonstrate_helper_methods( &ws )?;
33
34 // 4. Debug methods demonstration
35 println!( "\n4️⃣ Debug Methods:" );
36 demonstrate_debug_methods( &ws )?;
37
38 // 5. Migration examples
39 println!( "\n5️⃣ Migration Examples:" );
40 demonstrate_migration_patterns( &ws )?;
41
42 cleanup_demo_files( &ws );
43
44 println!( "\n🎉 Enhanced Secrets API Demo Complete!" );
45 println!( "Key improvements:" );
46 println!( " • No more silent failures - explicit errors with helpful suggestions" );
47 println!( " • Path vs filename clarity - warnings guide correct usage" );
48 println!( " • New path-aware methods for flexible secret loading" );
49 println!( " • Debug helpers for troubleshooting secret issues" );
50 println!( " • Better error messages with resolved paths and available files" );
51
52 Ok( () )
53}
examples/workspace_basic_usage.rs (line 18)
7fn main() -> Result< (), WorkspaceError >
8{
9 // ensure we have a workspace path set
10 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 // get workspace instance
17 println!( "resolving workspace..." );
18 let ws = workspace()?;
19
20 println!( "workspace root: {}", ws.root().display() );
21
22 // demonstrate standard directory access
23 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 // demonstrate path joining
31 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 // demonstrate workspace boundary checking
41 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 // validate workspace
46 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}