Reorganize the project layout, fix some logging quirks

Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
This commit is contained in:
2025-12-30 19:13:42 -03:00
parent a2a93adfb6
commit 613576f438
11 changed files with 44 additions and 41 deletions

View File

@@ -5,6 +5,6 @@ VERSION ?= `git describe --tags`
REVISION ?= `git rev-list --all | wc -l`
build:
@${GO} build ${GOFLAGS} -o mikuru ./cmd
@${GO} build ${GOFLAGS}
clean:
@rm -f mikuru

View File

@@ -6,8 +6,7 @@ env:
GO: go
vars:
IMPORT: git.laidback.moe/shinyoukai/mikuru
DIR: ./cmd
IMPORT: git.laidback.moe/shinyoukai/mikuru/mirai
tasks:
default:
cmds:
@@ -15,7 +14,7 @@ tasks:
build:
desc: Build the client
cmds:
- $GO build -ldflags='-s -w -X "{{.IMPORT}}.Version={{.VERSION}}" -X "{{.IMPORT}}.Revision={{.REVISION}}"' -v -o mikuru {{.DIR}}
- $GO build -ldflags='-s -w -X "{{.IMPORT}}.Version={{.VERSION}}" -X "{{.IMPORT}}.Revision={{.REVISION}}"' -v
vars:
REVISION:
sh: git rev-list --all | wc -l | tr -d ' '

View File

@@ -3,7 +3,7 @@ package main
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"git.laidback.moe/shinyoukai/mikuru"
"git.laidback.moe/shinyoukai/mikuru/mirai"
"go.yarn.social/client"
)
@@ -12,8 +12,8 @@ var followCmd = &cobra.Command{
Short: "Track a twtxt.txt feed, located in a Yarn pod or otherwise",
Run: func(_ *cobra.Command, args []string) {
cli, err := client.NewClient(
client.WithURI(mikuru.Config.Host),
client.WithToken(mikuru.Config.Token),
client.WithURI(mirai.Config.Host),
client.WithToken(mirai.Config.Token),
)
if err != nil {
log.Fatal(err)
@@ -32,7 +32,7 @@ var followCmd = &cobra.Command{
}
func init() {
mikuru.ConfInit()
mirai.ConfInit()
rootCmd.AddCommand(followCmd)
}

View File

@@ -7,7 +7,7 @@ import (
"golang.org/x/term"
"go.yarn.social/client"
"git.laidback.moe/shinyoukai/mikuru"
"git.laidback.moe/shinyoukai/mikuru/mirai"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@@ -24,16 +24,16 @@ var loginCmd = &cobra.Command{
Aliases: []string{"auth", "signin"},
Args: cobra.MaximumNArgs(0),
Run: func(_ *cobra.Command, _ []string) {
cli, err := client.NewClient(client.WithURI(mikuru.Config.Host))
cli, err := client.NewClient(client.WithURI(mirai.Config.Host))
if err != nil {
log.Fatal("Unable to create client", err)
log.Fatalf("Unable to create client\n%s\n", err)
}
signin(cli)
},
}
func init() {
mikuru.ConfInit()
mirai.ConfInit()
rootCmd.AddCommand(loginCmd)
}
@@ -49,7 +49,7 @@ func signin(cli *client.Client) {
fmt.Printf("Password: ")
data, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal("Unable to obtain password", err)
log.Fatalf("Unable to obtain password\n%s\n", err)
}
password := string(data)
@@ -57,7 +57,7 @@ func signin(cli *client.Client) {
res, err := cli.Login(username, password)
if err != nil {
log.Fatal("Unable to login", err)
log.Fatalf("Unable to login\n%s\n", err)
}
token := strings.Trim(fmt.Sprintf(res.Token), "{}")

View File

@@ -1,4 +1,4 @@
package mikuru
package mirai
import (
"log"

17
mirai/version.go Normal file
View File

@@ -0,0 +1,17 @@
package mirai
import (
"fmt"
)
var (
Revision = "0"
Version = "0"
)
func FullVersion() string {
return fmt.Sprintf("%s (r%s)", Version, Revision)
}
func PrintVersion() string {
return fmt.Sprintf("%s", Version)
}

View File

@@ -1,7 +1,7 @@
package main
import (
"git.laidback.moe/shinyoukai/mikuru"
"git.laidback.moe/shinyoukai/mikuru/mirai"
"go.yarn.social/client"
"github.com/tj/go-editor"
log "github.com/sirupsen/logrus"
@@ -14,11 +14,11 @@ var postCmd = &cobra.Command{
Short: "Publish a new post to a Yarn pod",
Run: func(_ *cobra.Command, args []string) {
cli, err := client.NewClient(
client.WithURI(mikuru.Config.Host),
client.WithToken(mikuru.Config.Token),
client.WithURI(mirai.Config.Host),
client.WithToken(mirai.Config.Token),
)
if err != nil {
log.Fatal("Unable to create client", err)
log.Fatalf("Unable to create client\n%s\n", err)
}
write(cli)
},
@@ -26,7 +26,7 @@ var postCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(postCmd)
mikuru.ConfInit()
mirai.ConfInit()
}
func write(cli *client.Client) {
@@ -35,7 +35,7 @@ func write(cli *client.Client) {
data, err := editor.Read()
if err != nil {
log.Fatal("Unable to read content from editor", err)
log.Fatalf("Unable to read content from editor\n%s\n", err)
}
post = string(data)
@@ -43,6 +43,6 @@ func write(cli *client.Client) {
_, err = cli.Post(post, "")
if err != nil {
log.Fatal("Unable to publish tweet", err)
log.Fatalf("Unable to publish tweet\n%s\n", err)
}
}

View File

@@ -3,13 +3,13 @@ package main
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"git.laidback.moe/shinyoukai/mikuru"
"git.laidback.moe/shinyoukai/mikuru/mirai"
)
var rootCmd = &cobra.Command{
Use: "mikuru",
Short: "A client for Yarn.social from the future",
Version: mikuru.Version,
Version: mirai.FullVersion(),
}
func Execute() {

View File

@@ -3,7 +3,7 @@ package main
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"git.laidback.moe/shinyoukai/mikuru"
"git.laidback.moe/shinyoukai/mikuru/mirai"
"go.yarn.social/client"
)
@@ -12,8 +12,8 @@ var unfollowCmd = &cobra.Command{
Short: "Cease to track a feed",
Run: func(_ *cobra.Command, args []string) {
cli, err := client.NewClient(
client.WithURI(mikuru.Config.Host),
client.WithToken(mikuru.Config.Token),
client.WithURI(mirai.Config.Host),
client.WithToken(mirai.Config.Token),
)
if err != nil {
log.Fatal(err)
@@ -31,7 +31,7 @@ var unfollowCmd = &cobra.Command{
}
func init() {
mikuru.ConfInit()
mirai.ConfInit()
rootCmd.AddCommand(unfollowCmd)
}

View File

@@ -1,13 +0,0 @@
package mikuru
import (
"fmt"
)
var (
Version = "0"
)
func PrintVersion() string {
return fmt.Sprintf("%s", Version)
}