Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CheckCommand = &cobra.Command{ Use: "check", Aliases: []string{"c"}, Long: "check command walks the specified paths recursively and checks if the specified files have the license header in the config file.", RunE: func(_ *cobra.Command, args []string) error { hasErrors := false for _, h := range Config.Headers() { var result header.Result if len(args) > 0 { logger.Log.Debugln("Overriding paths with command line args.") h.Paths = args } if err := header.Check(h, &result); err != nil { return err } logger.Log.Infoln(result.String()) writeSummaryQuietly(&result) if result.HasFailure() { if err := review.Header(&result, h); err != nil { logger.Log.Warnln("Failed to create review comments", err) } hasErrors = true logger.Log.Error(result.Error()) } } if hasErrors { return fmt.Errorf("one or more files does not have a valid license header") } return nil }, }
View Source
var (
Config config.Config
)
View Source
var Deps = &cobra.Command{ Use: "dependency", Aliases: []string{"d", "deps", "dep", "dependencies"}, Short: "Dependencies related commands; e.g. check, etc.", Long: "deps command checks all dependencies of a module and their transitive dependencies.", }
View Source
var DepsCheckCommand = &cobra.Command{ Use: "check", Aliases: []string{"c"}, Long: "resolves and check license compatibility in all dependencies of a module and their transitive dependencies", RunE: func(_ *cobra.Command, _ []string) error { var errors []error configDeps := Config.Dependencies() for _, header := range Config.Headers() { if err := deps.Check(header.License.SpdxID, configDeps, weakCompatible); err != nil { errors = append(errors, err) } } if len(errors) > 0 { for _, err := range errors { logger.Log.Error(err) } return fmt.Errorf("one or more errors occurred checking license compatibility") } return nil }, }
View Source
var DepsResolveCommand = &cobra.Command{ Use: "resolve", Aliases: []string{"r"}, Long: "resolves all dependencies of a module and their transitive dependencies", PreRunE: func(_ *cobra.Command, _ []string) error { if outDir != "" { absPath, err := filepath.Abs(outDir) if err != nil { return err } outDir = absPath if err := os.MkdirAll(outDir, 0o700); err != nil && !os.IsExist(err) { return err } } if summaryTplPath != "" { absPath, err := filepath.Abs(summaryTplPath) if err != nil { return err } summaryTplPath = absPath tpl, err := deps.ParseTemplate(os.DirFS(filepath.Dir(absPath)), filepath.Base(absPath)) if err != nil { return err } summaryTpl = tpl } if licensePath != "" { absPath, err := filepath.Abs(licensePath) if err != nil { return err } licensePath = absPath if err := os.MkdirAll(filepath.Dir(outDir), 0o700); err != nil && !os.IsExist(err) { return err } if summaryTpl == nil { tpl, err := deps.ParseTemplate(assets.FS(), "default-license.tpl") if err != nil { return err } summaryTpl = tpl } } return nil }, RunE: func(_ *cobra.Command, _ []string) error { report := deps.Report{} configDeps := Config.Dependencies() if err := deps.Resolve(configDeps, &report); err != nil { return err } if summaryTpl != nil { if err := writeSummary(&report, licensePath); err != nil { return err } } if outDir != "" { for _, result := range report.Resolved { writeLicense(result) } } fmt.Println(report.String()) if skipped := len(report.Skipped); skipped > 0 { pkgs := make([]string, skipped) for i, s := range report.Skipped { pkgs[i] = s.Dependency } return fmt.Errorf( "failed to identify the licenses of following packages (%d):\n%s", len(pkgs), strings.Join(pkgs, "\n"), ) } return nil }, }
View Source
var FixCommand = &cobra.Command{ Use: "fix", Aliases: []string{"f"}, Long: "fix command walks the specified paths recursively and fix the license header if the specified files don't have the license header.", RunE: func(_ *cobra.Command, args []string) error { var errors []string for _, h := range Config.Headers() { var result header.Result var files []string if len(args) > 0 { files = args } else if err := header.Check(h, &result); err != nil { return err } else { files = result.Failure } for _, file := range files { if err := header.Fix(file, h, &result); err != nil { errors = append(errors, err.Error()) } } logger.Log.Infoln(result.String()) } if len(errors) > 0 { return fmt.Errorf("%s", strings.Join(errors, "\n")) } return nil }, }
View Source
var Header = &cobra.Command{ Use: "header", Aliases: []string{"h"}, Short: "License header related commands; e.g. check, fix, etc.", Long: "`header` command walks the specified paths recursively and checks if the specified files have the license header in the config file.", }
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.