(globalFlags *flag.GlobalFlagGroup)
| 686 | } |
| 687 | |
| 688 | func NewConfigCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command { |
| 689 | scanFlags := &flag.ScanFlagGroup{ |
| 690 | // Enable only '--skip-dirs', '--skip-files', `--skip-version-check` |
| 691 | // and `--disable-telemetry`, disable other scan flags |
| 692 | SkipDirs: flag.SkipDirsFlag.Clone(), |
| 693 | SkipFiles: flag.SkipFilesFlag.Clone(), |
| 694 | FilePatterns: flag.FilePatternsFlag.Clone(), |
| 695 | SkipVersionCheck: flag.SkipVersionCheckFlag.Clone(), |
| 696 | DisableTelemetry: flag.DisableTelemetryFlag.Clone(), |
| 697 | } |
| 698 | |
| 699 | reportFlagGroup := flag.NewReportFlagGroup() |
| 700 | reportFlagGroup.DependencyTree = nil // disable '--dependency-tree' |
| 701 | reportFlagGroup.ListAllPkgs = nil // disable '--list-all-pkgs' |
| 702 | reportFlagGroup.ExitOnEOL = nil // disable '--exit-on-eol' |
| 703 | reportFlagGroup.ShowSuppressed = nil // disable '--show-suppressed' |
| 704 | reportFlagGroup.ReportFormat.Usage = "specify a compliance report format for the output" // @TODO: support --report summary for non compliance reports |
| 705 | |
| 706 | cacheFlagGroup := flag.NewCacheFlagGroup() |
| 707 | cacheFlagGroup.CacheBackend.Default = string(cache.TypeMemory) |
| 708 | |
| 709 | configFlags := &flag.Flags{ |
| 710 | globalFlags, |
| 711 | cacheFlagGroup, |
| 712 | flag.NewMisconfFlagGroup(), |
| 713 | flag.NewModuleFlagGroup(), |
| 714 | flag.NewRegistryFlagGroup(), |
| 715 | flag.NewRegoFlagGroup(), |
| 716 | &flag.K8sFlagGroup{ |
| 717 | // Keep only --k8s-version flag and disable others |
| 718 | K8sVersion: flag.K8sVersionFlag.Clone(), |
| 719 | }, |
| 720 | reportFlagGroup, |
| 721 | scanFlags, |
| 722 | } |
| 723 | |
| 724 | cmd := &cobra.Command{ |
| 725 | Use: "config [flags] DIR", |
| 726 | Aliases: []string{"conf"}, |
| 727 | GroupID: groupScanning, |
| 728 | Short: "Scan config files for misconfigurations", |
| 729 | PreRunE: func(cmd *cobra.Command, args []string) error { |
| 730 | if err := configFlags.Bind(cmd); err != nil { |
| 731 | return xerrors.Errorf("flag bind error: %w", err) |
| 732 | } |
| 733 | return validateArgs(cmd, args) |
| 734 | }, |
| 735 | RunE: func(cmd *cobra.Command, args []string) error { |
| 736 | if err := configFlags.Bind(cmd); err != nil { |
| 737 | return xerrors.Errorf("flag bind error: %w", err) |
| 738 | } |
| 739 | options, err := configFlags.ToOptions(args) |
| 740 | if err != nil { |
| 741 | return xerrors.Errorf("flag error: %w", err) |
| 742 | } |
| 743 | |
| 744 | // Disable OS and language analyzers |
| 745 | options.DisabledAnalyzers = append(analyzer.TypeOSes, analyzer.TypeLanguages...) |
no test coverage detected
searching dependent graphs…