Skip to content

Commit

Permalink
[RFE] close #113
Browse files Browse the repository at this point in the history
  • Loading branch information
gmeghnag committed Jan 2, 2024
1 parent 6ba29d7 commit ccaf241
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions cmd/use/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package use
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"slices"

Check failure on line 23 in cmd/use/use.go

View workflow job for this annotation

GitHub Actions / build

cannot find package "." in:
"strconv"
"strings"

Expand All @@ -45,7 +45,7 @@ func useContext(path string, omcConfigFile string, idFlag string) {
}

// read json omcConfigFile
file, _ := ioutil.ReadFile(omcConfigFile)
file, _ := os.ReadFile(omcConfigFile)
omcConfigJson := types.Config{}
_ = json.Unmarshal([]byte(file), &omcConfigJson)

Expand All @@ -68,7 +68,18 @@ func useContext(path string, omcConfigFile string, idFlag string) {
NewContexts = append(NewContexts, types.Context{Id: idFlag, Path: path, Current: "*", Project: "default"})
} else {
ctxId = helpers.RandString(8)
NewContexts = append(NewContexts, types.Context{Id: ctxId, Path: path, Current: "*", Project: "default"})
var namespaces []string
_namespaces, _ := os.ReadDir(path + "/namespaces/")
for _, f := range _namespaces {
namespaces = append(namespaces, f.Name())
}
if len(namespaces) == 1 {
NewContexts = append(NewContexts, types.Context{Id: ctxId, Path: path, Current: "*", Project: namespaces[0]})
} else if len(namespaces) > 1 && slices.Contains(namespaces, "openshift-logging") {
NewContexts = append(NewContexts, types.Context{Id: ctxId, Path: path, Current: "*", Project: "openshift-logging"})
} else {
NewContexts = append(NewContexts, types.Context{Id: ctxId, Path: path, Current: "*", Project: "default"})
}
}

}
Expand All @@ -83,7 +94,7 @@ func useContext(path string, omcConfigFile string, idFlag string) {
}
}
file, _ = json.MarshalIndent(config, "", " ")
_ = ioutil.WriteFile(omcConfigFile, file, 0644)
_ = os.WriteFile(omcConfigFile, file, 0644)

}

Expand All @@ -94,7 +105,7 @@ func findMustGatherIn(path string) (string, error) {
var retErr error
timeStampFound := false
namespacesFolderFound := false
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -169,17 +180,17 @@ var UseCmd = &cobra.Command{
isDir, _ := helpers.IsDirectory(path)
if !isDir {
isCompressedFile, _ = IsCompressedFile(path)
if (!isCompressedFile) {
fmt.Fprintln(os.Stderr, "Error: "+path+" is not a directory not a compressed file.")
os.Exit(1)
if !isCompressedFile {
fmt.Fprintln(os.Stderr, "Error: "+path+" is not a directory not a compressed file.")
os.Exit(1)
}
}
}

if (isCompressedFile) {
if isCompressedFile {
outputpath := filepath.Dir(path)
rootfile,err := DecompressFile(path,outputpath)
if ( err != nil ) {
rootfile, err := DecompressFile(path, outputpath)
if err != nil {
fmt.Fprintln(os.Stderr, "Error: decompressing "+path+" in "+outputpath+": "+err.Error())
os.Exit(1)
}
Expand Down

0 comments on commit ccaf241

Please sign in to comment.