interactionsCmd

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BoxCmd = &cobra.Command{
	Use:   "box",
	Short: "Interact with Box.com (list, upload, download)",
	Long: `Provides commands to interact with Box.com.
Requires a credentials.json file with client_id and client_secret,
which can be specified via a flag or placed at ~/.anbu-box-credentials.json.`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		if boxFlags.credentialsFile == "" {
			homeDir, err := os.UserHomeDir()
			if err != nil {
				return fmt.Errorf("failed to get user home directory: %w", err)
			}
			boxFlags.credentialsFile = filepath.Join(homeDir, ".anbu-box-credentials.json")
		}
		if _, err := os.Stat(boxFlags.credentialsFile); os.IsNotExist(err) {
			return fmt.Errorf("credentials file not found at %s. Please provide one using the --credentials flag or place it at the default location", boxFlags.credentialsFile)
		}
		return nil
	},
}
View Source
var FSSyncCmd = &cobra.Command{
	Use:   "fs-sync",
	Short: "One-shot file synchronization over HTTP/HTTPS",
	Long: `One-shot file synchronization between two machines.
Server side runs 'serve' and waits for one client connection.
Client side runs 'sync' to connect and sync files.
Both commands exit after sync completes.`,
}
View Source
var GDriveCmd = &cobra.Command{
	Use:     "gdrive",
	Aliases: []string{"gd"},
	Short:   "Interact with Google Drive (list, upload, download)",
	Long: `Provides commands to interact with Google Drive.
Requires a credentials.json file, which can be specified via a flag
or placed at ~/.anbu-gdrive-credentials.json.`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		if gdriveFlags.credentialsFile == "" {
			homeDir, err := os.UserHomeDir()
			if err != nil {
				return fmt.Errorf("failed to get user home directory: %w", err)
			}
			gdriveFlags.credentialsFile = filepath.Join(homeDir, ".anbu-gdrive-credentials.json")
		}
		if _, err := os.Stat(gdriveFlags.credentialsFile); os.IsNotExist(err) {
			return fmt.Errorf("credentials file not found at %s. Please provide one using the --credentials flag or place it at the default location", gdriveFlags.credentialsFile)
		}
		return nil
	},
}
View Source
var GitHubCmd = &cobra.Command{
	Use:     "github",
	Aliases: []string{"gh"},
	Short:   "Interact with GitHub (list, add, make, download)",
	Long: `Provides commands to interact with GitHub.
Requires a json file with client_id of Oauth app,
which can be specified via a flag or placed at
~/.anbu-github-credentials.json.`,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		if githubFlags.pat != "" {
			return nil
		}
		if githubFlags.credentialsFile == "" {
			homeDir, err := os.UserHomeDir()
			if err != nil {
				return fmt.Errorf("failed to get user home directory: %w", err)
			}
			githubFlags.credentialsFile = filepath.Join(homeDir, ".anbu-github-credentials.json")
		}
		if _, err := os.Stat(githubFlags.credentialsFile); os.IsNotExist(err) {
			return fmt.Errorf("credentials file not found at %s. Please provide one using the --credentials flag or place it at the default location", githubFlags.credentialsFile)
		}
		return nil
	},
}
View Source
var Neo4jCmd = &cobra.Command{
	Use:   "neo4j",
	Short: "Interact with a Neo4j database",
	Long: `Run Cypher queries against a Neo4j database from a string or a file.
The query file should be a YAML file containing a list of queries.
Multi-line queries are supported using the '|' character in YAML.

Example (single query):
  anbu interactions neo4j -q "MATCH (n) RETURN n LIMIT 5"

Example (query file):
  anbu interactions neo4j --query-file ./queries.yaml --output-file results.json`,
	Run: func(cmd *cobra.Command, args []string) {
		if neo4jCmdFlags.query != "" && neo4jCmdFlags.queryFile != "" {
			log.Fatal().Msg("please provide either a query or a query file, not both")
		}
		if neo4jCmdFlags.query == "" && neo4jCmdFlags.queryFile == "" {
			log.Fatal().Msg("a query or a query file is required")
		}

		ctx := context.Background()
		var results []interactions.QueryResult
		var err error
		if neo4jCmdFlags.query != "" {
			log.Debug().Msgf("executing single query: %s", neo4jCmdFlags.query)
			results, err = interactions.ExecuteNeo4jQueries(ctx, neo4jCmdFlags.uri, neo4jCmdFlags.user, neo4jCmdFlags.password, neo4jCmdFlags.database, []string{neo4jCmdFlags.query}, neo4jCmdFlags.writeMode)
		} else {
			log.Debug().Msgf("executing queries from file: %s", neo4jCmdFlags.queryFile)
			results, err = interactions.ExecuteNeo4jQueriesFromFile(ctx, neo4jCmdFlags.uri, neo4jCmdFlags.user, neo4jCmdFlags.password, neo4jCmdFlags.database, neo4jCmdFlags.queryFile, neo4jCmdFlags.writeMode)
		}
		if err != nil {
			log.Fatal().Err(err).Msg("failed to execute neo4j queries")
		}

		jsonData, err := json.MarshalIndent(results, "", "  ")
		if err != nil {
			log.Fatal().Err(err).Msg("failed to marshal results to JSON")
		}
		err = os.WriteFile(neo4jCmdFlags.outputFile, jsonData, 0644)
		if err != nil {
			log.Fatal().Err(err).Msgf("failed to write results to file: %s", neo4jCmdFlags.outputFile)
		}
		log.Info().Msgf("Successfully executed queries and saved results to %s", neo4jCmdFlags.outputFile)
	},
}

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