text

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TextCmd = &cobra.Command{
		Use:           "text",
		Short:         "searches the texts in files which has desired file name pattern and string pattern in it (supports regex)",
		SilenceUsage:  false,
		SilenceErrors: true,
		Example: `# search a text on target bucket by specifying regex for files
s3-manager search text "catch me if you can" --file-name=".*.txt"
		`,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			var rootOpts *rootopts.RootOptions
			svc, rootOpts, logger, _ = utils.PrepareConstants(cmd)
			searchOpts.RootOptions = rootOpts

			if err := utils.CheckArgs(args, 1); err != nil {
				logger.Error().Msg(err.Error())
				return err
			}

			searchOpts.Text = args[0]

			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) (err error) {
			logger.Info().
				Str("fileName", searchOpts.FileName).
				Msg("trying to search files on target bucket")

			matchedFiles, errs := aws.SearchString(svc, searchOpts)
			if len(errs) != 0 {
				err := fmt.Errorf("multiple errors occurred while searching files, try to target individual files %s", errs)
				logger.Error().Str("error", err.Error())
				return err
			}

			if len(matchedFiles) == 0 {
				logger.Info().
					Any("matchedFiles", matchedFiles).
					Str("text", searchOpts.Text).
					Msg("no matched files on the bucket")
				return nil
			}

			logger.Info().
				Str("text", searchOpts.Text).
				Msg("fetched below matching files")

			for _, v := range matchedFiles {
				fmt.Println(v)
			}

			return nil
		},
	}
)

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL