Version printing from command line arguments

This commit is contained in:
Magnus Åhall 2026-07-03 09:09:55 +02:00
parent fdc0fc8b97
commit b76502c034

33
main.go
View file

@ -36,6 +36,7 @@ var (
FlagConfig string
FlagCreateUser string
FlagChangePassword string
FlagVersion bool
Webengine HTMLTemplate.Engine
config Config
Log *slog.Logger
@ -66,6 +67,7 @@ func init() { // {{{
flag.BoolVar(&FlagLoremIpsum, "lorem-ipsum", false, "Replace all G- nodes with lorem ipsum paragraphs")
flag.StringVar(&FlagCreateUser, "create-user", "", "Username for creating a new user")
flag.StringVar(&FlagChangePassword, "change-password", "", "Change the password for the given username")
flag.BoolVar(&FlagVersion, "version", false, "Print version and exit")
flag.Parse()
RxpBearerToken = regexp.MustCompile("(?i)^\\s*Bearer\\s+(.*?)\\s*$")
@ -76,7 +78,14 @@ func initLog() { // {{{
Log = slog.New(slog.NewJSONHandler(os.Stdout, &opts))
} // }}}
func main() { // {{{
if FlagVersion {
fmt.Println(VERSION)
return
}
initLog()
Log.Info("application", "version", VERSION)
err := readConfig(FlagConfig)
if err != nil {
Log.Error("config", "error", err)
@ -502,7 +511,7 @@ func actionUserSetPreferences(w http.ResponseWriter, r *http.Request) { // {{{
})
} // }}}
func actionFileCount(w http.ResponseWriter, r *http.Request) {// {{{
func actionFileCount(w http.ResponseWriter, r *http.Request) { // {{{
session := getUserSession(r)
count, err := FileCountForUser(session.UserID)
if err != nil {
@ -512,11 +521,11 @@ func actionFileCount(w http.ResponseWriter, r *http.Request) {// {{{
}
responseData(w, map[string]any{
"OK": true,
"OK": true,
"Count": count,
})
}// }}}
func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) {// {{{
} // }}}
func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) { // {{{
session := getUserSession(r)
offset, _ := strconv.Atoi(r.PathValue("offset"))
uuids, more, err := FileServerUUIDsForUser(session.UserID, offset)
@ -527,12 +536,12 @@ func actionFileServerUUIDs(w http.ResponseWriter, r *http.Request) {// {{{
}
responseData(w, map[string]any{
"OK": true,
"UUIDs": uuids,
"OK": true,
"UUIDs": uuids,
"MoreRowsExist": more,
})
}// }}}
func actionFile(w http.ResponseWriter, r *http.Request) {// {{{
} // }}}
func actionFile(w http.ResponseWriter, r *http.Request) { // {{{
uuid := r.PathValue("uuid")
session := getUserSession(r)
f, md, err := FileForUser(session.UserID, uuid)
@ -543,8 +552,8 @@ func actionFile(w http.ResponseWriter, r *http.Request) {// {{{
}
http.ServeContent(w, r, md.Name, md.Modified, f)
}// }}}
func actionFileMetadata(w http.ResponseWriter, r *http.Request) {// {{{
} // }}}
func actionFileMetadata(w http.ResponseWriter, r *http.Request) { // {{{
uuid := r.PathValue("uuid")
session := getUserSession(r)
md, err := FileMetadata(session.UserID, uuid)
@ -556,10 +565,10 @@ func actionFileMetadata(w http.ResponseWriter, r *http.Request) {// {{{
}
responseData(w, map[string]any{
"OK": true,
"OK": true,
"Metadata": md,
})
}// }}}
} // }}}
func createNewUser(username string) { // {{{
reader := bufio.NewReader(os.Stdin)