add angela init command to scaffold pyproject.toml with config
This commit is contained in:
parent
fb109314f0
commit
b0c58a529d
|
|
@ -60,6 +60,7 @@ latest stable versions, and checks for known CVEs using OSV.dev.`,
|
|||
)
|
||||
|
||||
root.AddCommand(
|
||||
newInitCmd(),
|
||||
newUpdateCmd(),
|
||||
newCheckCmd(),
|
||||
newScanCmd(),
|
||||
|
|
@ -72,6 +73,55 @@ latest stable versions, and checks for known CVEs using OSV.dev.`,
|
|||
}
|
||||
}
|
||||
|
||||
const pyprojectTemplate = `[project]
|
||||
name = "%s"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
requires-python = ">=3.13"
|
||||
dependencies = []
|
||||
|
||||
[tool.angela]
|
||||
# Minimum severity to report (critical, high, moderate, low)
|
||||
# min-severity = "moderate"
|
||||
|
||||
# Dependencies to skip during updates
|
||||
# ignore = []
|
||||
|
||||
# Vulnerability IDs to suppress (accepted risk)
|
||||
# ignore-vulns = []
|
||||
`
|
||||
|
||||
func newInitCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Create a new pyproject.toml with angela configuration",
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
return runInit()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func runInit() error {
|
||||
if _, err := os.Stat("pyproject.toml"); err == nil {
|
||||
return fmt.Errorf("pyproject.toml already exists")
|
||||
}
|
||||
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return fmt.Errorf("get working directory: %w", err)
|
||||
}
|
||||
|
||||
name := filepath.Base(dir)
|
||||
content := fmt.Sprintf(pyprojectTemplate, name)
|
||||
|
||||
if err := os.WriteFile("pyproject.toml", []byte(content), 0o644); err != nil { //nolint:gosec
|
||||
return fmt.Errorf("write pyproject.toml: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\n %s pyproject.toml\n\n", greenBold("Created"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func newUpdateCmd() *cobra.Command {
|
||||
f := &updateFlags{}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue