Skip to content

Commit

Permalink
Updated config to be written into its own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves Ulrich Tittes committed Jan 22, 2025
1 parent 36d9521 commit b415493
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 12 additions & 3 deletions configuration/setgetconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Getconfig() ([]byte, error) {
if err != nil {
return nil, err
}
configFilePath := filepath.Join(path, "LS_reader.conf")
configFilePath := filepath.Join(path, "LS_Metadata_reader/LS_reader.conf")

_, err1 := os.Stat(configFilePath)
if err1 != nil {
Expand All @@ -35,8 +35,16 @@ func Changeconfig() {
if err != nil {
fmt.Println("Couldn't reach config directory", err)
}
configFilePath := filepath.Join(path, "LS_reader.conf")

configFilePath := filepath.Join(path, "LS_Metadata_reader/LS_reader.conf")
configdir := filepath.Join(path, "LS_Metadata_reader")
_, err1 := os.Stat(configdir)
if err1 != nil {
if os.IsNotExist(err1) {
os.Mkdir(configdir, 0755)
} else {
fmt.Printf("Error accessing %q: %v\n", configdir, err1)
}
}
fmt.Println("What is your instruments spherical aberration (CS)?")
reader := bufio.NewReader(os.Stdin)
input1, err := reader.ReadString('\n')
Expand Down Expand Up @@ -67,6 +75,7 @@ func Changeconfig() {
fmt.Fprintln(os.Stderr, "Error generating config:", err)
return
}

err = os.WriteFile(configFilePath, config, 0644)
if err != nil {
fmt.Fprintln(os.Stderr, "Error generating config:", err)
Expand Down
8 changes: 3 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ func main() {
// allow for reconfiguration of the config
if *cFlag {
current, err := configuration.Getconfig()
var grid map[string]string
if err != nil {
fmt.Fprintln(os.Stderr, " No prior config obtainable", err)
}
var grid map[string]string
err1 := json.Unmarshal(current, &grid)
if err1 != nil {
fmt.Fprintln(os.Stderr, "Config exists but reading it failed", err)
}
_ = json.Unmarshal(current, &grid)
fmt.Println("current config:\n", grid)
configuration.Changeconfig()
return
}
var directory string
// Check that there are arguments
Expand Down

0 comments on commit b415493

Please sign in to comment.