Skip to content

Commit

Permalink
Add the ability to specify the home directory for files using COHCTL_…
Browse files Browse the repository at this point in the history
…HOME (#241)

* Add the ability to specify the home directory for files using COHCTL_HOME

* Add test for COHCTL_HOME
  • Loading branch information
tmiddlet2666 authored Oct 22, 2024
1 parent a27d5eb commit 7fc9f48
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
27 changes: 22 additions & 5 deletions docs/config/10_changing_config_locations.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2021, 2023 Oracle and/or its affiliates.
Copyright (c) 2021, 2024 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at
https://oss.oracle.com/licenses/upl.

Expand All @@ -10,10 +10,28 @@
== Changing Config Locations
By default, the CLI creates a directory `.cohctl` off the users home to store connection information,
By default, the CLI creates a directory `.cohctl` off the user's home to store connection information,
log files and various other information.
If you wish to change this directory from the default, you can use the following for each command.
NOTE: It is recommended to leave these values as default unless you have a good reason to change them.
If you do want to change the location, setting the `COHCTL_HOME` environment variable is the best option
otherwise you would need to specify the `--config` option on each command execution.
If you wish to change this directory from the default, you can use the following options:
=== Set COHCTL_HOME environment variable
You can set the environment variable `COHCTL_HOME` to change the location of the directory where the CLI creates it's files.
[source,bash]
----
export COHCTL_HOME=/u01/config
----
All subsequent command executions will use this directory. The directory will be created if it doesn't exist
and will throw an error if you don't have permissions to create it.
=== Specify the directory for each command
[source,bash]
----
Expand All @@ -27,7 +45,6 @@ You can also specify a different location for the `cohct.yaml` file that is gene
cohctl get clusters --config /u01/my-config.yaml
----
NOTE: It is recommended to leave these values as default unless you have a good reason to change them
as you would need to specify the `--config` option on each command execution.
5 changes: 5 additions & 0 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ func initConfig() {
home string
)

// if cfgDirectory not specified then check for env variable COHCTL_HOME to override default
if cfgDirectory == "" {
cfgDirectory = os.Getenv("COHCTL_HOME")
}

if cfgDirectory != "" {
// --config-dir set so ensure we create the directory if it doesn't exist
if stat, err := os.Stat(cfgDirectory); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions scripts/test-create-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ if [ -z "$COM" -a -z "`echo $VERSION | grep SNAPSHOT`" ] ; then
runCommand remove cluster local -y
fi

# Test the environment variable for setting the home directory
message "Setting COHCTL_HOME to ${CONFIG_DIR}"
export COHCTL_HOME=${CONFIG_DIR}
$DIR/bin/cohctl version



Expand Down

0 comments on commit 7fc9f48

Please sign in to comment.