cmd

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "iccheck",
	Short: "Finds inconsistent changes in your git changes",
	Long: fmt.Sprintf(`ICCheck %v
Finds inconsistent changes in your git changes.`, cli.GetFormattedVersion()),
	Version:      cli.GetFormattedVersion(),
	SilenceUsage: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(timeoutSeconds))
		defer cancel()

		if err := setLogLevel(); err != nil {
			return err
		}
		repoDir, err := getRepoDir()
		if err != nil {
			return err
		}
		repo, err := git.PlainOpen(repoDir)
		if err != nil {
			return errors.Wrapf(err, "opening repository at %v", repoDir)
		}
		searchConf, err := searchConfig(repoDir)
		if err != nil {
			return err
		}

		if fromRef == "" && toRef != "" {

			fromRef = toRef + "^"
		} else if fromRef != "" && toRef == "" {
			return errors.New("only one of --from was set, this is invalid - do not set for automatic discovery or set both")
		} else if fromRef == "" && toRef == "" {
			fromRef, toRef, err = autoDetermineRefs(repo)
			if err != nil {
				return errors.Wrapf(err, "determining refs")
			}
		}

		fromTree, err := resolveTree(repo, fromRef)
		if err != nil {
			return errors.Wrap(err, "resolving base tree")
		}
		toTree, err := resolveTree(repo, toRef)
		if err != nil {
			return errors.Wrap(err, "resolving target tree")
		}

		queries, changedFiles, err := search.DiffTrees(ctx, fromTree, toTree)
		if err != nil {
			return err
		}
		slog.Info(fmt.Sprintf("%d changed text chunk(s) were found within %d changed file(s).", len(queries), changedFiles), "from", fromTree, "to", toTree)
		for i, q := range queries {
			slog.Debug(fmt.Sprintf("Query#%d", i), "query", q)
		}
		cloneSets, err := search.Search(ctx, algorithm, queries, toTree, searchConf)
		if err != nil {
			return err
		}
		reportClones(cloneSets)
		return nil
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳