ficsit-cli-flake/tools.go

85 lines
1.5 KiB
Go
Raw Normal View History

2021-12-02 04:00:33 +00:00
//go:build tools
// +build tools
2022-06-08 20:56:32 +00:00
package main
2021-12-02 04:00:33 +00:00
2022-06-08 20:56:32 +00:00
import (
2022-10-14 16:11:16 +00:00
"os"
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
"os/user"
"path/filepath"
"runtime"
"strings"
2022-10-14 16:11:16 +00:00
2022-06-08 20:56:32 +00:00
"github.com/spf13/cobra/doc"
2022-10-14 16:11:16 +00:00
"github.com/satisfactorymodding/ficsit-cli/cmd"
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
_ "github.com/Khan/genqlient/generate"
2022-06-08 20:56:32 +00:00
)
2021-12-02 04:00:33 +00:00
//go:generate go run github.com/Khan/genqlient
2022-10-14 16:11:16 +00:00
//go:generate go run -tags tools tools.go
2022-06-08 20:56:32 +00:00
func main() {
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
var err error
2022-06-08 20:56:32 +00:00
_ = os.RemoveAll("./docs/")
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
if err = os.Mkdir("./docs/", 0o777); err != nil {
panic(err)
}
err = doc.GenMarkdownTree(cmd.RootCmd, "./docs/")
if err != nil {
2022-06-08 20:56:32 +00:00
panic(err)
}
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
// replace user dir information with generic username
baseCacheDir, err := os.UserCacheDir()
2022-06-08 20:56:32 +00:00
if err != nil {
panic(err)
}
feat: compatibility info display in View Mod screen. log to ficsit-cli.log by default (#33) * fix: log by default (ficsit-cli.log in CWD) * chore: update readme with info on code generation * chore: regenerate docs for default log file location * feat: compatibility info state and note display. wip: keybind to switch view modes not working * fix: move render code out to a function, but it still isn't quite working yet * feat: display mod reference below mod name * Fix compat toggle with * Show scroll up/down on quick help * chore: fix merge conflict * chore: run go install mvdan.cc/gofumpt@latest; gofumpt -l -w . * chore: run gci.exe write --skip-generated -s standard -s default -s 'prefix(github.com/satisfactorymodding/ficsit-cli)' -s blank -s dot . * chore: update readme linting info and run golangci-lint --version * fix: log file is defaulted to empty again * fix(#33): update render to return just string * fix(#33): renderModInfo returns only string * fix(#33): reollback func namechange * refactor(#33): remove redundant viewport refresh * refactor(#33): update is not required after setting content * refactor(#33): remove unrequired log * docs(#33): update documentation to latest generated * docs(#33): update cache reference to not contain username * docs(#33): fix local dir references too * refactor(#33): replace vague variable with more helpful * Add directions about using dev schema when generate command fails * Fix issues from earlier merge conflict --------- Co-authored-by: Jack Stupple <jack.stupple@protonmail.com>
2023-12-28 02:32:56 +00:00
var baseLocalDir string
switch runtime.GOOS {
case "windows":
baseLocalDir = os.Getenv("APPDATA")
case "linux":
baseLocalDir = filepath.Join(os.Getenv("HOME"), ".local", "share")
default:
panic("unsupported platform: " + runtime.GOOS)
}
docFiles, err := os.ReadDir("./docs/")
if err != nil {
panic(err)
}
user, err := user.Current()
if err != nil {
panic(err)
}
for _, f := range docFiles {
fPath := "./docs/" + f.Name()
oldContents, err := os.ReadFile(fPath)
if err != nil {
panic(err)
}
newContents := strings.ReplaceAll(
string(oldContents),
baseCacheDir,
strings.ReplaceAll(baseCacheDir, user.Username, "{{Username}}"),
)
newContents = strings.ReplaceAll(
newContents,
baseLocalDir,
strings.ReplaceAll(baseLocalDir, user.Username, "{{Username}}"),
)
os.WriteFile(fPath, []byte(newContents), 0o777)
}
2022-06-08 20:56:32 +00:00
}