Skip to content

Commit a11b0d0

Browse files
domenkozarclaude
andcommitted
refactor: improve init command output formatting
- Generate cleaner TOML with proper sectioning via generate_toml_with_comments() - Simplify example template by removing redundant comments - Update hint message to suggest 'secretspec check' instead of 'set' - Add project configuration file 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e098ec8 commit a11b0d0

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

secretspec.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[project]
2+
name = "secretspec"
3+
revision = "1.0"
4+
# Extend configurations from subdirectories
5+
# extends = [ "subdir1", "subdir2" ]
6+
7+
[profiles.default]
8+
# API_KEY = { description = "API key for external service", required = true }
9+
# DATABASE_URL = { description = "Database connection string", required = true }
10+
11+
[profiles.development]
12+
# API_KEY = { description = "API key for external service", required = false, default = "dev-api-key" }
13+
# DATABASE_URL = { description = "Database connection string", required = true, default = "sqlite:///dev.db" }
14+
# JWT_SECRET = { description = "Secret key for JWT token signing", required = true }
15+
# REDIS_URL = { description = "Redis connection URL for caching", required = false, default = "redis://localhost:6379" }
16+
# EMAIL_PROVIDER = { description = "Email service provider", required = false, default = "console" }
17+
# OAUTH_CLIENT_ID = { description = "OAuth client ID", required = false }
18+
# OAUTH_CLIENT_SECRET = { description = "OAuth client secret", required = false }

src/lib.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,9 @@ pub fn project_config_from_path(from: &Path) -> Result<ProjectConfig> {
112112
}
113113

114114
pub fn get_example_toml() -> &'static str {
115-
r#"
116-
# Example secrets configuration
117-
# Uncomment and modify the sections you need
118-
119-
# API_KEY = { description = "API key for external service", required = true }
115+
r#"# API_KEY = { description = "API key for external service", required = true }
120116
# DATABASE_URL = { description = "Database connection string", required = true }
121117
122-
# Extend configurations from subdirectories
123-
# extends = [ "subdir1", "subdir2" ]
124-
125118
[profiles.development]
126119
# API_KEY = { description = "API key for external service", required = false, default = "dev-api-key" }
127120
# DATABASE_URL = { description = "Database connection string", required = true, default = "sqlite:///dev.db" }
@@ -133,6 +126,39 @@ pub fn get_example_toml() -> &'static str {
133126
"#
134127
}
135128

129+
pub fn generate_toml_with_comments(config: &ProjectConfig) -> Result<String> {
130+
let mut output = String::new();
131+
132+
// Project section
133+
output.push_str("[project]\n");
134+
output.push_str(&format!("name = \"{}\"\n", config.project.name));
135+
output.push_str(&format!("revision = \"{}\"\n", config.project.revision));
136+
137+
// Add extends comment and field if needed
138+
output.push_str("# Extend configurations from subdirectories\n");
139+
output.push_str("# extends = [ \"subdir1\", \"subdir2\" ]\n");
140+
141+
// Profile sections
142+
for (profile_name, profile_config) in &config.profiles {
143+
output.push_str(&format!("\n[profiles.{}]\n", profile_name));
144+
145+
for (secret_name, secret_config) in &profile_config.secrets {
146+
output.push_str(&format!(
147+
"{} = {{ description = \"{}\", required = {}",
148+
secret_name, secret_config.description, secret_config.required
149+
));
150+
151+
if let Some(default) = &secret_config.default {
152+
output.push_str(&format!(", default = \"{}\"", default));
153+
}
154+
155+
output.push_str(" }\n");
156+
}
157+
}
158+
159+
Ok(output)
160+
}
161+
136162
pub struct SecretSpec {
137163
registry: ProviderRegistry,
138164
config: ProjectConfig,
@@ -241,7 +267,7 @@ impl SecretSpec {
241267
"!".yellow(),
242268
from.display()
243269
);
244-
println!(" secretspec set <SECRET_NAME>");
270+
println!(" secretspec check");
245271
}
246272

247273
Ok(())

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn main() -> Result<()> {
117117
match cli.command {
118118
Commands::Init { from } => {
119119
let project_config = secretspec::project_config_from_path(&from)?;
120-
let mut content = toml::to_string_pretty(&project_config)?;
120+
let mut content = secretspec::generate_toml_with_comments(&project_config)?;
121121

122122
// Append comprehensive example
123123
content.push_str(secretspec::get_example_toml());

0 commit comments

Comments
 (0)