Skip to content

Commit 7fc9f48

Browse files
author
Tim Middleton
authored
Add the ability to specify the home directory for files using COHCTL_HOME (#241)
* Add the ability to specify the home directory for files using COHCTL_HOME * Add test for COHCTL_HOME
1 parent a27d5eb commit 7fc9f48

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

docs/config/10_changing_config_locations.adoc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///////////////////////////////////////////////////////////////////////////////
22

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

@@ -10,10 +10,28 @@
1010
1111
== Changing Config Locations
1212
13-
By default, the CLI creates a directory `.cohctl` off the users home to store connection information,
13+
By default, the CLI creates a directory `.cohctl` off the user's home to store connection information,
1414
log files and various other information.
1515
16-
If you wish to change this directory from the default, you can use the following for each command.
16+
NOTE: It is recommended to leave these values as default unless you have a good reason to change them.
17+
If you do want to change the location, setting the `COHCTL_HOME` environment variable is the best option
18+
otherwise you would need to specify the `--config` option on each command execution.
19+
20+
If you wish to change this directory from the default, you can use the following options:
21+
22+
=== Set COHCTL_HOME environment variable
23+
24+
You can set the environment variable `COHCTL_HOME` to change the location of the directory where the CLI creates it's files.
25+
26+
[source,bash]
27+
----
28+
export COHCTL_HOME=/u01/config
29+
----
30+
31+
All subsequent command executions will use this directory. The directory will be created if it doesn't exist
32+
and will throw an error if you don't have permissions to create it.
33+
34+
=== Specify the directory for each command
1735
1836
[source,bash]
1937
----
@@ -27,7 +45,6 @@ You can also specify a different location for the `cohct.yaml` file that is gene
2745
cohctl get clusters --config /u01/my-config.yaml
2846
----
2947
30-
NOTE: It is recommended to leave these values as default unless you have a good reason to change them
31-
as you would need to specify the `--config` option on each command execution.
48+
3249
3350

pkg/cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ func initConfig() {
276276
home string
277277
)
278278

279+
// if cfgDirectory not specified then check for env variable COHCTL_HOME to override default
280+
if cfgDirectory == "" {
281+
cfgDirectory = os.Getenv("COHCTL_HOME")
282+
}
283+
279284
if cfgDirectory != "" {
280285
// --config-dir set so ensure we create the directory if it doesn't exist
281286
if stat, err := os.Stat(cfgDirectory); err != nil {

scripts/test-create-cluster.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ if [ -z "$COM" -a -z "`echo $VERSION | grep SNAPSHOT`" ] ; then
310310
runCommand remove cluster local -y
311311
fi
312312

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

314318

315319

0 commit comments

Comments
 (0)