Skip to content

Commit 2abca03

Browse files
waveywavesclaude
andcommitted
feat(cli): allow setting project name in .chainloop.yaml
Extend DotChainloopConfig to support a `project` field so that `chainloop attestation init` can read the project name from the config file when the --project flag is not provided. Precedence: CLI flag > .chainloop.yaml > default. Example .chainloop.yaml: project: my-project projectVersion: v1.2.0 Note: organization override from .chainloop.yaml is not included in this PR because the org is baked into the gRPC connection credentials during PersistentPreRunE, before att init's PreRunE runs. Supporting org override requires loading the config earlier in the command lifecycle — left for follow-up discussion. Fixes: #3063 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Vibhav Bobade <vibhav.bobde@gmail.com>
1 parent bb484cd commit 2abca03

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

app/cli/cmd/attestation_init.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ func newAttestationInitCmd() *cobra.Command {
5555
return errors.New("workflow name is required, set it via --workflow flag")
5656
}
5757

58-
// load version from the file if not set and not using --latest-version
59-
if projectVersion == "" && !useLatestVersion {
60-
// load the cfg from the file
58+
// Load project name and version from .chainloop.yaml when the
59+
// corresponding CLI flags are not provided.
60+
// Precedence: CLI flag > .chainloop.yaml > default/auto-discovery.
61+
if projectName == "" || (projectVersion == "" && !useLatestVersion) {
6162
cfg, path, err := loadDotChainloopConfigWithParentTraversal()
62-
// we do gracefully load, if not found, or any other error we continue
6363
if err != nil {
6464
logger.Debug().Msgf("failed to load chainloop config: %s", err)
65-
return nil
65+
} else {
66+
if projectName == "" && cfg.Project != "" {
67+
logger.Debug().Msgf("loaded project %q from config file %s", cfg.Project, path)
68+
projectName = cfg.Project
69+
}
70+
if projectVersion == "" && !useLatestVersion && cfg.ProjectVersion != "" {
71+
logger.Debug().Msgf("loaded version %q from config file %s", cfg.ProjectVersion, path)
72+
projectVersion = cfg.ProjectVersion
73+
}
6674
}
67-
68-
logger.Debug().Msgf("loaded version %s from config file %s", cfg.ProjectVersion, path)
69-
70-
projectVersion = cfg.ProjectVersion
7175
}
7276

7377
if useLatestVersion && projectVersion != "" {
@@ -173,8 +177,7 @@ func newAttestationInitCmd() *cobra.Command {
173177
cmd.Flags().StringVar(&workflowName, "workflow-name", "", "name of the workflow to run the attestation")
174178
cobra.CheckErr(cmd.Flags().MarkDeprecated("workflow-name", "please use --workflow instead"))
175179

176-
cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow")
177-
cobra.CheckErr(cmd.MarkFlagRequired("project"))
180+
cmd.Flags().StringVar(&projectName, "project", "", "name of the project of this workflow (can also be set in .chainloop.yaml)")
178181
cmd.Flags().StringVar(&newWorkflowcontract, "contract", "", "name of an existing contract or the path/URL to a contract file, to attach it to the auto-created workflow (it doesn't update an existing one)")
179182

180183
cmd.Flags().StringVar(&projectVersion, "version", "", "project version, i.e 0.1.0")

app/cli/cmd/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ func isDir(filename string) bool {
161161

162162
type DotChainloopConfig struct {
163163
ProjectVersion string `yaml:"projectVersion"`
164+
Project string `yaml:"project"`
165+
Organization string `yaml:"organization"`
164166
}

0 commit comments

Comments
 (0)