Skip to content

Commit

Permalink
Make --new-config accept path from --config. Closes #410.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jun 29, 2021
1 parent ea9895e commit 5e2c24b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 4 additions & 5 deletions cmd/install.go
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -161,9 +160,9 @@ func recordMigrationVersion(ver string, db *sqlx.DB) error {
return err
}

func newConfigFile() error {
if _, err := os.Stat("config.toml"); !os.IsNotExist(err) {
return errors.New("config.toml exists. Remove it to generate a new one")
func newConfigFile(path string) error {
if _, err := os.Stat(path); !os.IsNotExist(err) {
return fmt.Errorf("%s exists. Remove it to generate a new one.", path)
}

// Initialize the static file system into which all
Expand All @@ -181,7 +180,7 @@ func newConfigFile() error {
ReplaceAll(b, []byte(fmt.Sprintf(`admin_password = "%s"`, pwd)))
}

return ioutil.WriteFile("config.toml", b, 0644)
return ioutil.WriteFile(path, b, 0644)
}

// checkSchema checks if the DB schema is installed.
Expand Down
5 changes: 3 additions & 2 deletions cmd/main.go
Expand Up @@ -85,11 +85,12 @@ func init() {

// Generate new config.
if ko.Bool("new-config") {
if err := newConfigFile(); err != nil {
path := ko.Strings("config")[0]
if err := newConfigFile(path); err != nil {
lo.Println(err)
os.Exit(1)
}
lo.Println("generated config.toml. Edit and run --install")
lo.Printf("generated %s. Edit and run --install", path)
os.Exit(0)
}

Expand Down

0 comments on commit 5e2c24b

Please sign in to comment.