Compare commits

...

2 Commits

Author SHA1 Message Date
decentral1se 25229f1ea8
feat: log files to user directory
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details
2023-12-29 19:04:45 +01:00
decentral1se e4ce9b6552
feat: version handling 2023-12-29 18:54:41 +01:00
3 changed files with 67 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"os/user"
"path"
"d1.hackers.moe/cairde/ui"
@ -16,10 +17,24 @@ import (
tea "github.com/charmbracelet/bubbletea"
)
const (
var (
// Version is the current version of Cairde (LDFLAGS).
Version string
// Commit is the current git commit of Cairde (LDFLAGS).
Commit string
// help is the command-line help output.
help = `cairde [options]
A terminal client for metadata resistant messaging built on the Cwtch protocol.
_________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/
/ / / /| | / // /_/ / / / / __/
/ /___/ ___ |_/ // _, _/ /_/ / /___
\____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging
%s
Options:
-a turn on the Tor ACN immediately
@ -30,6 +45,14 @@ Options:
)
func main() {
if Version == "" {
Version = "pre-alpha"
}
if Commit == "" {
Commit = " "
}
cairdeVersion := fmt.Sprintf("%s commit %s", Version, Commit[:7])
var (
acnFlag bool
debugFlag bool
@ -44,39 +67,53 @@ func main() {
flag.Parse()
if helpFlag {
fmt.Print(help)
fmt.Print(fmt.Sprintf(help, cairdeVersion))
os.Exit(0)
}
if versionFlag {
fmt.Print("cairde pre-alpha v0.1.0") // TODO
fmt.Printf("%s\n", cairdeVersion)
os.Exit(0)
}
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
_, err := exec.LookPath("tor")
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
if err != nil {
log.Fatal("could not find 'tor' command, is it installed?")
log.Fatal("main: could not find 'tor' command, is it installed?")
}
f, err := tea.LogToFile("cairde.log", "debug")
user, err := user.Current()
if err != nil {
log.Fatalf("main: unable to determine current user: %s", err)
}
userDir := path.Join(user.HomeDir, "/.cairde/")
if err := os.Mkdir(userDir, 0764); err != nil {
if !os.IsExist(err) {
log.Fatalf("main: unable to create user directory: %s", err)
}
}
cairdeLogPath := path.Join(userDir, "cairde.log")
f, err := tea.LogToFile(cairdeLogPath, "debug")
if err != nil {
log.Fatal(err)
}
defer f.Close()
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log")
cwtchLogPath := path.Join(userDir, "cwtch.log")
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, cwtchLogPath)
if err == nil {
openPrivacyLog.SetStd(filelogger)
}
user, err := user.Current()
if err != nil {
log.Fatalf("unable to determine current user: %s", err)
}
p := tea.NewProgram(
ui.NewModel(user.Username, user.HomeDir, debugFlag),
ui.NewModel(
user.Username,
user.HomeDir,
cairdeVersion,
debugFlag,
),
tea.WithAltScreen(),
tea.WithMouseAllMotion(),
)

View File

@ -1,3 +1,7 @@
COMMIT := $(shell git rev-list -1 HEAD)
LDFLAGS := "-X 'main.Commit=$(COMMIT)'"
DIST_LDFLAGS := $(LDFLAGS)" -s -w"
.PHONY: format check clean build run loc test
DEFAULT: run
@ -13,10 +17,11 @@ ci:
@golangci-lint run ./...
clean:
@find -type f -name "*.log" -exec rm '{}' \;
@go clean && \
find ~/.cairde -type f -name "*.log" -exec rm '{}' \;
build: clean
@go build -ldflags="-s -w" -v ./cmd/cairde
@go build -ldflags=$(DIST_LDFLAGS) ./cmd/cairde
run: build
@./cairde

View File

@ -17,7 +17,7 @@ import (
"github.com/charmbracelet/lipgloss"
)
const (
var (
welcomeMessage = `
_________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/
@ -26,7 +26,7 @@ const (
\____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging
Pre-alpha v0.1.0
%s
Run /start for the getting started guide.
Run /help to see all available commands.`
@ -82,12 +82,14 @@ type model struct {
input textinput.Model
hiddenInput string
version string
statusBuffer chan string
debug bool
}
func NewModel(username, homeDir string, debug bool) model { // nolint:revive
func NewModel(username, homeDir, version string, debug bool) model { // nolint:revive
input := textinput.New()
input.Prompt = "> "
input.PromptStyle = inputPromptStyle
@ -107,6 +109,8 @@ func NewModel(username, homeDir string, debug bool) model { // nolint:revive
input: input,
version: version,
statusBuffer: make(chan string),
showWelcomeMessage: true,
@ -195,8 +199,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
if m.showWelcomeMessage {
withVersion := fmt.Sprintf(welcomeMessage, m.version)
cmds = append(cmds, m.sendStatusCmd(
strings.Split(welcomeMessage, "\n")...,
strings.Split(withVersion, "\n")...,
))
m.showWelcomeMessage = false
}