1 Commits

Author SHA1 Message Date
613576f438 Reorganize the project layout, fix some logging quirks
Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
2025-12-30 19:13:42 -03:00
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` REVISION ?= `git rev-list --all | wc -l`
build: build:
@${GO} build ${GOFLAGS} -o mikuru ./cmd @${GO} build ${GOFLAGS}
clean: clean:
@rm -f mikuru @rm -f mikuru

View File

@@ -6,8 +6,7 @@ env:
GO: go GO: go
vars: vars:
IMPORT: git.laidback.moe/shinyoukai/mikuru IMPORT: git.laidback.moe/shinyoukai/mikuru/mirai
DIR: ./cmd
tasks: tasks:
default: default:
cmds: cmds:
@@ -15,7 +14,7 @@ tasks:
build: build:
desc: Build the client desc: Build the client
cmds: 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: vars:
REVISION: REVISION:
sh: git rev-list --all | wc -l | tr -d ' ' sh: git rev-list --all | wc -l | tr -d ' '

View File

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

View File

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

View File

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

View File

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

View File

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