ficsit-cli-flake/cli/disk/local.go
Rob B e313efdfec
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 04:32:56 +02:00

72 lines
1.3 KiB
Go

package disk
import (
"errors"
"fmt"
"io"
"os"
)
var _ Disk = (*localDisk)(nil)
type localDisk struct {
path string
}
type localEntry struct {
os.DirEntry
}
func newLocal(path string) (Disk, error) {
return localDisk{path: path}, nil
}
func (l localDisk) Exists(path string) (bool, error) {
_, err := os.Stat(path)
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
if err != nil {
return false, fmt.Errorf("failed checking file existence: %w", err)
}
return true, nil
}
func (l localDisk) Read(path string) ([]byte, error) {
return os.ReadFile(path) //nolint
}
func (l localDisk) Write(path string, data []byte) error {
return os.WriteFile(path, data, 0o777) //nolint
}
func (l localDisk) Remove(path string) error {
return os.RemoveAll(path) //nolint
}
func (l localDisk) MkDir(path string) error {
return os.MkdirAll(path, 0o777) //nolint
}
func (l localDisk) ReadDir(path string) ([]Entry, error) {
dir, err := os.ReadDir(path)
if err != nil {
return nil, err //nolint
}
entries := make([]Entry, len(dir))
for i, entry := range dir {
entries[i] = localEntry{
DirEntry: entry,
}
}
return entries, nil
}
func (l localDisk) Open(path string, flag int) (io.WriteCloser, error) {
return os.OpenFile(path, flag, 0o777) //nolint
}