config gropple portable #13

Closed
opened 2022-02-05 09:22:56 +10:30 by candrapersada · 6 comments
candrapersada commented 2022-02-05 09:22:56 +10:30 (Migrated from github.com)

why is config.yml not saved in the same folder as gropple.exe?

why is `config.yml` not saved in the same folder as `gropple.exe`?
tardisx commented 2022-02-05 10:44:05 +10:30 (Migrated from github.com)

It's pretty standard behaviour to store a config file in $HOME or similar, so the binary can be anywhere. What's your use case?

It's pretty standard behaviour to store a config file in $HOME or similar, so the binary can be anywhere. What's your use case?
candrapersada commented 2022-02-05 10:50:51 +10:30 (Migrated from github.com)

how to save config.yml in a portable folder so it's easy to use gropple without config from scratch again.

how to save `config.yml` in a portable folder so it's easy to use gropple without config from scratch again.
tardisx commented 2022-02-05 11:37:20 +10:30 (Migrated from github.com)

Do you mean you want to run it from a USB stick or similar? On multiple machines?

Do you mean you want to run it from a USB stick or similar? On multiple machines?
candrapersada commented 2022-02-05 11:50:45 +10:30 (Migrated from github.com)

Do you mean you want to run it from a USB stick or similar

yes

On multiple machines?

yes
image

> Do you mean you want to run it from a USB stick or similar yes > On multiple machines? yes ![image](https://user-images.githubusercontent.com/36833664/152623441-48ddf710-eb06-4f5e-8b54-fdb8a3d7f32b.png)
soulmaestro commented 2022-04-05 22:27:00 +09:30 (Migrated from github.com)

as this isn't answered (yet?), i suggest to edit 'config.go' lines 164 to 183 as followed:

original:

`func configPath() string {
dir, err := os.UserConfigDir()
if err != nil {
log.Fatalf("cannot find a directory to store config: %v", err)
}
appDir := "gropple"

fullPath := dir + string(os.PathSeparator) + appDir
_, err = os.Stat(fullPath)

if os.IsNotExist(err) {
	err := os.Mkdir(fullPath, 0777)
	if err != nil {
		log.Fatalf("Could not create config dir %s : %v", fullPath, err)
	}
}

fullFilename := fullPath + string(os.PathSeparator) + "config.yml"
return fullFilename

}`

edited version:

`func configPath() string {
dir, err := os.Executable()
if err != nil {
log.Fatalf("cannot find a directory to store config: %v", err)
}

// if you want to place config.yml in a subdir of the Current workdit of your .exe
// edit the // appDir := "config" line and remove the // infront of it, and place // infront of the appDir:="" line
// if you want to place config.yml next to your exe, leave the following 2 lines as shown

// appDir := "config"
appDir := ""

if appDir != "" {
	fullPath := dir + string(os.PathSeparator) + appDir
} else {
	fullPath := dir
}
_, err = os.Stat(fullPath)

if os.IsNotExist(err) {
	err := os.Mkdir(fullPath, 0777)
	if err != nil {
		log.Fatalf("Could not create config dir %s: %v", fullPath, err)
	}
}

fullFilename := fullPath + string(os.PathSeparator) + "config.yml"
return fullFilename

}`

ps: this is untested, and like a first Golang-edit for me, but that should do would you want.

as this isn't answered (yet?), i suggest to edit 'config.go' lines 164 to 183 as followed: original: `func configPath() string { dir, err := os.UserConfigDir() if err != nil { log.Fatalf("cannot find a directory to store config: %v", err) } appDir := "gropple" fullPath := dir + string(os.PathSeparator) + appDir _, err = os.Stat(fullPath) if os.IsNotExist(err) { err := os.Mkdir(fullPath, 0777) if err != nil { log.Fatalf("Could not create config dir %s : %v", fullPath, err) } } fullFilename := fullPath + string(os.PathSeparator) + "config.yml" return fullFilename }` edited version: `func configPath() string { dir, err := os.Executable() if err != nil { log.Fatalf("cannot find a directory to store config: %v", err) } // if you want to place config.yml in a subdir of the Current workdit of your .exe // edit the // appDir := "config" line and remove the // infront of it, and place // infront of the appDir:="" line // if you want to place config.yml next to your exe, leave the following 2 lines as shown // appDir := "config" appDir := "" if appDir != "" { fullPath := dir + string(os.PathSeparator) + appDir } else { fullPath := dir } _, err = os.Stat(fullPath) if os.IsNotExist(err) { err := os.Mkdir(fullPath, 0777) if err != nil { log.Fatalf("Could not create config dir %s: %v", fullPath, err) } } fullFilename := fullPath + string(os.PathSeparator) + "config.yml" return fullFilename }` ps: this is untested, and like a first Golang-edit for me, but that should do would you want.
soulmaestro commented 2022-04-05 22:34:50 +09:30 (Migrated from github.com)

pfff code-block insert is sh**t, oh well you should be able to figure it out with the above info

pfff code-block insert is sh**t, oh well you should be able to figure it out with the above info
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: justin/gropple#13
No description provided.