Skip to content

Commit 458d7c7

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 5141752 commit 458d7c7

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

app/cli/cmd/attestation_init.go

Lines changed: 15 additions & 12 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 != "" {
@@ -154,7 +158,7 @@ func newAttestationInitCmd() *cobra.Command {
154158
}
155159

156160
if projectName == "" {
157-
logger.Warn().Msg("DEPRECATION WARNING: --project not set, this will be required in the near future")
161+
logger.Warn().Msg("DEPRECATION WARNING: project not set via --project flag or .chainloop.yaml, this will be required in the near future")
158162
}
159163

160164
return output.EncodeOutput(flagOutputFormat, res, fullStatusTable)
@@ -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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,5 @@ func isDir(filename string) bool {
161161

162162
type DotChainloopConfig struct {
163163
ProjectVersion string `yaml:"projectVersion"`
164+
Project string `yaml:"project"`
164165
}

app/cli/documentation/cli-reference.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ Options
328328
--existing-version return an error if the version doesn't exist in the project
329329
-h, --help help for init
330330
--latest-version use the latest existing project version instead of specifying one
331-
--project string name of the project of this workflow
331+
--project string name of the project of this workflow (can also be set in .chainloop.yaml)
332332
--release promote the provided version as a release
333333
--remote-state Store the attestation state remotely
334334
-f, --replace replace any existing in-progress attestation

0 commit comments

Comments
 (0)