Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,34 @@ For full command reference, see the list below, or visit

**Management Commands**

| Commands | Description |
| ------------------------------ | -------------------------------------------- |
| axiom auth login | Login to an Axiom deployment |
| axiom auth logout | Logout of an Axiom deployment |
| axiom auth select | Select an Axiom deployment |
| axiom auth status | View authentication status |
| axiom auth switch-org | Switch the organization |
| axiom auth update-token | Update the token of a deloyment |
| axiom config edit | Edit the configuration file |
| axiom config get | Get a configuration value |
| axiom config set | Set a configuration value |
| axiom dataset create | Create a dataset |
| axiom dataset delete | Delete a dataset |
| axiom dataset info | Get info about a dataset |
| axiom dataset list | List all datasets |
| axiom dataset stats | Get statistics about all datasets |
| axiom dataset trim | Trim a dataset to a given size |
| axiom dataset update | Update a dataset |
| axiom organization info | Get info about an organization |
| axiom organization license | Get an organizations license |
| axiom organization list | List all organizations |
| axiom organization keys get | Get shared access keys of an organization |
| axiom organization keys rotate | Rotate shared access keys of an organization |
| axiom token api create | Create a token |
| axiom token api delete | Delete a token |
| axiom token personal create | Create a token |
| axiom token personal delete | Delete a token |
| Commands | Description |
| ------------------------------ | ---------------------------------------------------------- |
| axiom auth login | Login to an Axiom deployment |
| axiom auth logout | Logout of an Axiom deployment |
| axiom auth select | Select an Axiom deployment |
| axiom auth status | View authentication status |
| axiom auth switch-org | Switch the organization |
| axiom auth update-token | Update the token of a deloyment |
| axiom config edit | Edit the configuration file |
| axiom config get | Get a configuration value |
| axiom config set | Set a configuration value |
| axiom config export | Export the configuration values for the current deployment |
| axiom dataset create | Create a dataset |
| axiom dataset delete | Delete a dataset |
| axiom dataset info | Get info about a dataset |
| axiom dataset list | List all datasets |
| axiom dataset stats | Get statistics about all datasets |
| axiom dataset trim | Trim a dataset to a given size |
| axiom dataset update | Update a dataset |
| axiom organization info | Get info about an organization |
| axiom organization license | Get an organizations license |
| axiom organization list | List all organizations |
| axiom organization keys get | Get shared access keys of an organization |
| axiom organization keys rotate | Rotate shared access keys of an organization |
| axiom token api create | Create a token |
| axiom token api delete | Delete a token |
| axiom token personal create | Create a token |
| axiom token personal delete | Delete a token |

**Additional Commands**

Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func NewConfigCmd(f *cmdutil.Factory) *cobra.Command {

# Open the configuration file in the configured editor:
$ axiom config edit

# Export the configuration values AXIOM_URL, AXIOM_TOKEN and AXIOM_ORG_ID from the current deployment to the current terminal session:
$ eval $(axiom config export --force)
`),

Annotations: map[string]string{
Expand All @@ -36,6 +39,7 @@ func NewConfigCmd(f *cmdutil.Factory) *cobra.Command {
cmd.AddCommand(newEditCmd(f))
cmd.AddCommand(newGetCmd(f))
cmd.AddCommand(newSetCmd(f))
cmd.AddCommand(newExportCommand(f))

return cmd
}
Expand Down
74 changes: 74 additions & 0 deletions internal/cmd/config/config_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package config

import (
"fmt"

"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"

"github.com/axiomhq/cli/internal/cmdutil"
)

type exportOptions struct {
*cmdutil.Factory

// Required for the export command to execute.
Force bool
}

var forceMessage = heredoc.Doc(`You can not export the configuration values without the --force flag.
If you are sure you want to export the configuration values, run the command again with the --force flag.
Ensure that you eval this command, without doing so, the configuration values will not be exported.
Be aware that this may overwrite the existing environment variables and may also print the values to the console.`)

var successMessage = heredoc.Doc("Environment Variables set. If they don't seem to be set, ensure that this command was ran in an eval statement.")

func newExportCommand(f *cmdutil.Factory) *cobra.Command {
opts := &exportOptions{
Factory: f,
}

cmd := &cobra.Command{
Use: "export [-f|--force]",
Short: "Export the configuration values for the current deployment",
Long: `Export the configuration values AXIOM_URL, AXIOM_TOKEN and AXIOM_ORG_ID from the current deployment to the current terminal session.`,

DisableFlagsInUseLine: true,

ValidArgsFunction: keyCompletionFunc(f.Config),

Example: heredoc.Doc(`
# Export the configuration values AXIOM_URL, AXIOM_TOKEN and AXIOM_ORG_ID from the current deployment to the current terminal session:
$ eval $(axiom config export --force)
`),

RunE: func(_ *cobra.Command, args []string) error {
// check that the force flag was used
if !opts.Force {
fmt.Fprintf(opts.IO.ErrOut(), "%s %s\n", opts.IO.ColorScheme().ErrorIcon(), forceMessage)
return nil
}

// fetch current deployment
deployment, ok := f.Config.GetActiveDeployment()
if !ok {
return fmt.Errorf("no active deployment found")
}

// export environment variables
fmt.Fprintf(f.IO.Out(), `export AXIOM_URL="`+deployment.URL+`"`+"\n")
fmt.Fprintf(f.IO.Out(), `export AXIOM_TOKEN="`+deployment.Token+`"`+"\n")
fmt.Fprintf(f.IO.Out(), `export AXIOM_ORG_ID="`+deployment.OrganizationID+`"`+"\n")

fmt.Fprintf(opts.IO.ErrOut(), "%s %s\n", opts.IO.ColorScheme().SuccessIcon(), successMessage)

return nil
},
}

cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Allow for the export of the configuration values")

_ = cmd.RegisterFlagCompletionFunc("force", cmdutil.NoCompletion)

return cmd
}