Compare commits

...

3 commits

Author SHA1 Message Date
e898a1ded5
fix: fixed error when using --help flag
All checks were successful
REUSE Compliance Check / check (push) Successful in 8s
Parse the flags before loading the configuration to fix the error where
using the --help flag caused the app to return an error if the
configuration file does not exist.
2024-08-23 02:47:36 +01:00
987f8caa1c
fix: update the user agent 2024-08-23 02:40:13 +01:00
cc5e3f0044
refactor: move information values to info package
- Move the build and application information to the internal info
  package.
- Move the user agent and redirect URI string to the internal client
  package.
2024-08-23 02:35:30 +01:00
12 changed files with 169 additions and 170 deletions

View file

@ -129,6 +129,14 @@ func {{ $execute_command_function_name }}(
exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
{{- end -}}
{{- end -}}
{{ print "" }}
{{ print "" }}
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("({{ $name }}) flag parsing error: " + err.Error() + ".")
return err
}
{{- if $command.UseConfig -}}
{{ print "" }}
{{ print "" }}
@ -155,13 +163,6 @@ func {{ $execute_command_function_name }}(
{{- end -}}
{{ print "" }}
{{ print "" }}
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("({{ $name }}) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("({{ $name }}) execution error: " + err.Error() + ".")

View file

@ -10,12 +10,13 @@ import (
"os"
"time"
"codeflow.dananglin.me.uk/apollo/enbas/internal"
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
)
const (
applicationJSON string = "application/json; charset=utf-8"
redirectURI string = "urn:ietf:wg:oauth:2.0:oob"
userAgent string = "Enbas/0.2.0"
)
type Client struct {
@ -42,7 +43,7 @@ func NewClient(authentication config.Credentials) *Client {
gtsClient := Client{
Authentication: authentication,
HTTPClient: httpClient,
UserAgent: internal.UserAgent,
UserAgent: userAgent,
Timeout: 5 * time.Second,
}
@ -51,7 +52,7 @@ func NewClient(authentication config.Credentials) *Client {
func (g *Client) AuthCodeURL() string {
format := "%s/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"
escapedRedirectURI := url.QueryEscape(internal.RedirectURI)
escapedRedirectURI := url.QueryEscape(redirectURI)
return fmt.Sprintf(
format,

View file

@ -6,7 +6,7 @@ import (
"fmt"
"net/http"
"codeflow.dananglin.me.uk/apollo/enbas/internal"
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
)
@ -19,10 +19,10 @@ type registerRequest struct {
func (g *Client) Register() error {
registerParams := registerRequest{
ClientName: internal.ApplicationName,
RedirectUris: internal.RedirectURI,
ClientName: info.ApplicationName,
RedirectUris: redirectURI,
Scopes: "read write",
Website: internal.ApplicationWebsite,
Website: info.ApplicationWebsite,
}
data, err := json.Marshal(registerParams)

View file

@ -5,8 +5,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"codeflow.dananglin.me.uk/apollo/enbas/internal"
)
type tokenRequest struct {
@ -26,7 +24,7 @@ type tokenResponse struct {
func (g *Client) UpdateToken(code string) error {
tokenReq := tokenRequest{
RedirectURI: internal.RedirectURI,
RedirectURI: redirectURI,
ClientID: g.Authentication.ClientID,
ClientSecret: g.Authentication.ClientSecret,
GrantType: "authorization_code",

View file

@ -106,6 +106,13 @@ func ExecuteAcceptCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(accept) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -122,13 +129,6 @@ func ExecuteAcceptCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(accept) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(accept) execution error: " + err.Error() + ".")
@ -179,6 +179,13 @@ func ExecuteAddCommand(
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
exe.Var(&exe.votes, "vote", "Add a vote to an option in a poll")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(add) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -195,13 +202,6 @@ func ExecuteAddCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(add) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(add) execution error: " + err.Error() + ".")
@ -241,6 +241,13 @@ func ExecuteBlockCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(block) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -257,13 +264,6 @@ func ExecuteBlockCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(block) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(block) execution error: " + err.Error() + ".")
@ -351,6 +351,13 @@ func ExecuteCreateCommand(
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
exe.StringVar(&exe.visibility, "visibility", "", "The visibility of the posted status")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(create) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -367,13 +374,6 @@ func ExecuteCreateCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(create) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(create) execution error: " + err.Error() + ".")
@ -416,6 +416,13 @@ func ExecuteDeleteCommand(
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(delete) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -432,13 +439,6 @@ func ExecuteDeleteCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(delete) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(delete) execution error: " + err.Error() + ".")
@ -490,6 +490,13 @@ func ExecuteEditCommand(
exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(edit) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -506,13 +513,6 @@ func ExecuteEditCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(edit) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(edit) execution error: " + err.Error() + ".")
@ -556,6 +556,13 @@ func ExecuteFollowCommand(
exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(follow) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -572,13 +579,6 @@ func ExecuteFollowCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(follow) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(follow) execution error: " + err.Error() + ".")
@ -612,16 +612,16 @@ func ExecuteInitCommand(
exe.Usage = usage.ExecutorUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet)
// Create the printer for the executor.
exe.printer = printer.NewPrinter(noColor, "", 0)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(init) flag parsing error: " + err.Error() + ".")
printer.NewPrinter(noColor, "", 0).PrintFailure("(init) flag parsing error: " + err.Error() + ".")
return err
}
// Create the printer for the executor.
exe.printer = printer.NewPrinter(noColor, "", 0)
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(init) execution error: " + err.Error() + ".")
@ -658,6 +658,13 @@ func ExecuteLoginCommand(
exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(login) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -674,13 +681,6 @@ func ExecuteLoginCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(login) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(login) execution error: " + err.Error() + ".")
@ -727,6 +727,13 @@ func ExecuteMuteCommand(
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(mute) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -743,13 +750,6 @@ func ExecuteMuteCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(mute) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(mute) execution error: " + err.Error() + ".")
@ -789,6 +789,13 @@ func ExecuteRejectCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(reject) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -805,13 +812,6 @@ func ExecuteRejectCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(reject) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(reject) execution error: " + err.Error() + ".")
@ -857,6 +857,13 @@ func ExecuteRemoveCommand(
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(remove) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -873,13 +880,6 @@ func ExecuteRemoveCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(remove) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(remove) execution error: " + err.Error() + ".")
@ -958,6 +958,13 @@ func ExecuteShowCommand(
exe.StringVar(&exe.tag, "tag", "", "The name of the tag")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(show) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -974,13 +981,6 @@ func ExecuteShowCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(show) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(show) execution error: " + err.Error() + ".")
@ -1020,6 +1020,13 @@ func ExecuteSwitchCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.to, "to", "", "The resource type to action the target resource to (e.g. status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(switch) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -1036,13 +1043,6 @@ func ExecuteSwitchCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(switch) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(switch) execution error: " + err.Error() + ".")
@ -1082,6 +1082,13 @@ func ExecuteUnblockCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(unblock) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -1098,13 +1105,6 @@ func ExecuteUnblockCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(unblock) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(unblock) execution error: " + err.Error() + ".")
@ -1144,6 +1144,13 @@ func ExecuteUnfollowCommand(
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(unfollow) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -1160,13 +1167,6 @@ func ExecuteUnfollowCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(unfollow) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(unfollow) execution error: " + err.Error() + ".")
@ -1208,6 +1208,13 @@ func ExecuteUnmuteCommand(
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(unmute) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -1224,13 +1231,6 @@ func ExecuteUnmuteCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(unmute) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(unmute) execution error: " + err.Error() + ".")
@ -1267,16 +1267,16 @@ func ExecuteVersionCommand(
exe.BoolVar(&exe.full, "full", false, "Set to true to print the build information in full")
// Create the printer for the executor.
exe.printer = printer.NewPrinter(noColor, "", 0)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(version) flag parsing error: " + err.Error() + ".")
printer.NewPrinter(noColor, "", 0).PrintFailure("(version) flag parsing error: " + err.Error() + ".")
return err
}
// Create the printer for the executor.
exe.printer = printer.NewPrinter(noColor, "", 0)
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(version) execution error: " + err.Error() + ".")
@ -1310,6 +1310,13 @@ func ExecuteWhoamiCommand(
exe.Usage = usage.ExecutorUsageFunc("whoami", "Prints the account that you are currently logged into", exe.FlagSet)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
printer.NewPrinter(noColor, "", 0).PrintFailure("(whoami) flag parsing error: " + err.Error() + ".")
return err
}
// Load the configuration from file.
exeConfig, err := config.NewConfigFromFile(exe.configDir)
if err != nil {
@ -1326,13 +1333,6 @@ func ExecuteWhoamiCommand(
exe.config.LineWrapMaxWidth,
)
// Parse the remaining arguments.
if err := exe.Parse(args); err != nil {
exe.printer.PrintFailure("(whoami) flag parsing error: " + err.Error() + ".")
return err
}
// Run the executor.
if err := exe.Execute(); err != nil {
exe.printer.PrintFailure("(whoami) execution error: " + err.Error() + ".")

View file

@ -1,4 +1,9 @@
package version
package info
const (
ApplicationName string = "enbas"
ApplicationWebsite string = "https://codeflow.dananglin.me.uk/apollo/enbas"
)
var (
BinaryVersion string //nolint:gochecknoglobals

View file

@ -1,8 +0,0 @@
package internal
const (
ApplicationName = "enbas"
ApplicationWebsite = "https://codeflow.dananglin.me.uk/apollo/enbas"
RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
UserAgent = "Enbas/0.0.0"
)

View file

@ -4,12 +4,12 @@ import (
"strings"
"text/tabwriter"
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
)
func (p Printer) PrintVersion(showFullVersion bool) {
if !showFullVersion {
printToStdout("Enbas " + version.BinaryVersion + "\n")
printToStdout("Enbas " + info.BinaryVersion + "\n")
return
}
@ -20,10 +20,10 @@ func (p Printer) PrintVersion(showFullVersion bool) {
tableWriter := tabwriter.NewWriter(&builder, 0, 4, 1, ' ', 0)
_, _ = tableWriter.Write([]byte(p.fieldFormat("Version:") + "\t" + version.BinaryVersion + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Git commit:") + "\t" + version.GitCommit + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Go version:") + "\t" + version.GoVersion + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Build date:") + "\t" + version.BuildTime + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Version:") + "\t" + info.BinaryVersion + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Git commit:") + "\t" + info.GitCommit + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Go version:") + "\t" + info.GoVersion + "\n"))
_, _ = tableWriter.Write([]byte(p.fieldFormat("Build date:") + "\t" + info.BuildTime + "\n"))
tableWriter.Flush()

View file

@ -7,7 +7,7 @@ import (
"strings"
"text/tabwriter"
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
)
func AppUsageFunc() func() {
@ -24,13 +24,13 @@ func AppUsageFunc() func() {
return func() {
var builder strings.Builder
builder.WriteString("SUMMARY:\n enbas - A GoToSocial client for the terminal.\n\n")
builder.WriteString("SUMMARY:\n " + info.ApplicationName + " - A GoToSocial client for the terminal.\n\n")
if version.BinaryVersion != "" {
builder.WriteString("VERSION:\n " + version.BinaryVersion + "\n\n")
if info.BinaryVersion != "" {
builder.WriteString("VERSION:\n " + info.BinaryVersion + "\n\n")
}
builder.WriteString("USAGE:\n enbas [flags]\n enbas [flags] [command]\n\nCOMMANDS:")
builder.WriteString("USAGE:\n " + info.ApplicationName + " [flags]\n " + info.ApplicationName + " [flags] [command]\n\nCOMMANDS:")
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
@ -45,7 +45,7 @@ func AppUsageFunc() func() {
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
})
builder.WriteString("\n\nUse \"enbas [command] --help\" for more information about a command.\n")
builder.WriteString("\n\nUse \"" + info.ApplicationName + " [command] --help\" for more information about a command.\n")
w := flag.CommandLine.Output()
fmt.Fprint(w, builder.String())

View file

@ -4,6 +4,8 @@ import (
"flag"
"slices"
"strings"
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
)
// ExecutorUsageFunc returns the function used to print a command's help page.
@ -14,7 +16,7 @@ func ExecutorUsageFunc(name, summary string, flagset *flag.FlagSet) func() {
builder.WriteString("SUMMARY:")
builder.WriteString("\n " + name + " - " + summary)
builder.WriteString("\n\nUSAGE:")
builder.WriteString("\n enbas " + name)
builder.WriteString("\n " + info.ApplicationName + " " + name)
flagMap := make(map[string]string)

View file

@ -6,7 +6,7 @@ import (
"os"
"path/filepath"
"codeflow.dananglin.me.uk/apollo/enbas/internal"
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
)
const (
@ -24,7 +24,7 @@ func CalculateConfigDir(configDir string) (string, error) {
return "", fmt.Errorf("unable to get your default config diretory: %w", err)
}
return filepath.Join(configRoot, internal.ApplicationName), nil
return filepath.Join(configRoot, info.ApplicationName), nil
}
func CalculateMediaCacheDir(cacheRoot, instance string) (string, error) {
@ -57,7 +57,7 @@ func calculateCacheDir(cacheRoot, instance string) (string, error) {
return "", fmt.Errorf("unable to get your default cache directory: %w", err)
}
return filepath.Join(cacheRoot, internal.ApplicationName, fqdn), nil
return filepath.Join(cacheRoot, info.ApplicationName, fqdn), nil
}
func EnsureDirectory(dir string) error {

View file

@ -110,7 +110,7 @@ func Clean() error {
// ldflags returns the build flags.
func ldflags() string {
versionPackage := "codeflow.dananglin.me.uk/apollo/enbas/internal/version"
versionPackage := "codeflow.dananglin.me.uk/apollo/enbas/internal/info"
binaryVersionVar := versionPackage + "." + "BinaryVersion"
gitCommitVar := versionPackage + "." + "GitCommit"
goVersionVar := versionPackage + "." + "GoVersion"