// Copyright The gittuf Authors // SPDX-License-Identifier: Apache-2.0 package setrepositorylocation import ( "github.com/gittuf/gittuf/experimental/gittuf" trustpolicyopts "github.com/gittuf/gittuf/experimental/gittuf/options/trustpolicy" "github.com/gittuf/gittuf/internal/cmd/trust/persistent" "github.com/spf13/cobra" ) type options struct { p *persistent.Options location string } func (o *options) AddFlags(cmd *cobra.Command) { cmd.Flags().StringVar( &o.location, "location", "", "location of repository", ) cmd.MarkFlagRequired("location") //nolint:errcheck } func (o *options) Run(cmd *cobra.Command, _ []string) error { repo, err := gittuf.LoadRepository(".") if err != nil { return err } signer, err := gittuf.LoadSigner(repo, o.p.SigningKey) if err != nil { return err } opts := []trustpolicyopts.Option{} if o.p.WithRSLEntry { opts = append(opts, trustpolicyopts.WithRSLEntry()) } return repo.SetRepositoryLocation(cmd.Context(), signer, o.location, true, opts...) } func New(persistent *persistent.Options) *cobra.Command { o := &options{p: persistent} cmd := &cobra.Command{ Use: "set-repository-location", Short: "Set repository location", Long: "The 'set-repository-location' command updates the canonical location of a repository in the repository's root of trust. It is used to encode the canonical location of the repository inside gittuf metadata.", RunE: o.Run, DisableAutoGenTag: true, } o.AddFlags(cmd) return cmd }