Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.PHONY: help lint test tidy clear-cache

VERSION=1.2.3
BINARY_DIR=./bin
BINARY_NAME=noxdir

Expand All @@ -17,7 +18,7 @@ tidy: ## Upgrade dependencies and format code
go fmt ./...

build: ## Produce a binary
go build -ldflags "-s -w" -o ${BINARY_DIR}/${BINARY_NAME}
go build -ldflags "-s -w -X main.version=${VERSION}" -o ${BINARY_DIR}/${BINARY_NAME}

clear-cache:
go clean -cache && go clean -testcache && go clean -fuzzcache && go clean -modcache
23 changes: 10 additions & 13 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
ErrUnknown = errors.New("unknown error")

exclude []string
appVersion string
root string
sizeLimit string
noEmptyDirs bool
Expand Down Expand Up @@ -67,6 +68,8 @@ selected drive and presents the space consumption in a clear, user-friendly layo
)

func init() {
appCmd.SetVersionTemplate("{{.Version}}\n")

appCmd.PersistentFlags().StringSliceVarP(
&exclude,
"exclude",
Expand Down Expand Up @@ -220,11 +223,12 @@ Example: -v|--version (provide a flag)
)
}

func Execute() {
if err := appCmd.Execute(); err != nil {
var cliErr *CLIError
func Execute(version string) {
appVersion = version
appCmd.Version = version

if errors.As(err, &cliErr) {
if err := appCmd.Execute(); err != nil {
if cliErr, ok := errors.AsType[*CLIError](err); ok {
printError(cliErr.Error())
} else {
printError(render.ReportError(err, debug.Stack()))
Expand Down Expand Up @@ -270,14 +274,6 @@ func initConfig() (*config.Settings, error) {
}

func runApp(_ *cobra.Command, _ []string) error {
if versionFlag {
if _, err := os.Stdout.WriteString(render.Version + "\n"); err != nil {
return err
}

return nil
}

var (
err error
style *render.Style
Expand Down Expand Up @@ -335,8 +331,9 @@ func initViewModel(s *config.Settings) (*render.ViewModel, error) {
}

vm := render.NewViewModel(
appVersion,
nav,
render.NewDriveModel(nav),
render.NewDriveModel(appVersion, nav),
render.NewDirModel(nav, dirModelFilters...),
)

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/crumbyte/noxdir/cmd"
)

var version = "dev"

func main() {
cmd.Execute()
cmd.Execute(version)
}
6 changes: 4 additions & 2 deletions render/drive_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ type DriveModel struct {
statusBar *StatusBar
sortState SortState
view tea.View
version string
height int
width int
fullHelp bool
}

func NewDriveModel(n *Navigation) *DriveModel {
func NewDriveModel(version string, n *Navigation) *DriveModel {
pathRatio := DefaultColWidthRatio

if runtime.GOOS == "darwin" {
Expand Down Expand Up @@ -94,6 +95,7 @@ func NewDriveModel(n *Navigation) *DriveModel {
drivesTable: buildTable(),
statusBar: NewStatusBar(),
usagePG: &style.CS().UsageProgressBar,
version: version,
}
}

Expand Down Expand Up @@ -252,7 +254,7 @@ func (dm *DriveModel) drivesSummary() string {
}

barItems := []*BarItem{
{Content: Version, BGColor: sbStyle.VersionBG},
{Content: "v" + dm.version, BGColor: sbStyle.VersionBG},
{Content: "DRIVES", BGColor: sbStyle.Drives.ModeBG},
{Content: driveTitle, BGColor: sbStyle.BG, Width: -1},
}
Expand Down
17 changes: 10 additions & 7 deletions render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import (
"charm.land/lipgloss/v2"
)

const (
Version = "1.2.2"

updateTickerInterval = time.Millisecond * 500
)
const updateTickerInterval = time.Millisecond * 500

type (
UpdateDirState struct{}
Expand All @@ -32,15 +28,22 @@ type ViewModel struct {
driveModel *DriveModel
dirModel *DirModel
nav *Navigation
version string
lastErr []error
}

func NewViewModel(n *Navigation, driveModel *DriveModel, dirMode *DirModel) *ViewModel {
func NewViewModel(
version string,
n *Navigation,
driveModel *DriveModel,
dirMode *DirModel,
) *ViewModel {
return &ViewModel{
lastErr: make([]error, 0),
nav: n,
driveModel: driveModel,
dirModel: dirMode,
version: version,
}
}

Expand Down Expand Up @@ -97,7 +100,7 @@ func (vm *ViewModel) View() tea.View {
}

v.AltScreen = true
v.WindowTitle = "NoxDir " + Version
v.WindowTitle = "NoxDir | v" + vm.version
v.MouseMode = tea.MouseModeNone

return v
Expand Down
Loading