2020-10-25 15:06:51 +00:00
package main
import (
"flag"
2021-03-09 14:27:14 +00:00
"fmt"
2020-10-25 15:06:51 +00:00
"log"
2021-03-09 14:27:14 +00:00
"os"
2020-10-25 15:06:51 +00:00
"path/filepath"
2021-03-09 14:27:14 +00:00
"github.com/bouncepaw/mycorrhiza/assets"
2020-11-13 18:45:42 +00:00
"github.com/bouncepaw/mycorrhiza/user"
2020-10-25 15:06:51 +00:00
"github.com/bouncepaw/mycorrhiza/util"
)
2021-03-09 14:27:14 +00:00
var printExampleConfig bool
2020-10-25 15:06:51 +00:00
func init ( ) {
2021-03-06 09:40:47 +00:00
// flag.StringVar(&util.URL, "url", "http://0.0.0.0:$port", "URL at which your wiki can be found. Used to generate feeds and social media previews")
// flag.StringVar(&util.ServerPort, "port", "1737", "Port to serve the wiki at using HTTP")
// flag.StringVar(&util.HomePage, "home", "home", "The home page name")
// flag.StringVar(&util.SiteNavIcon, "icon", "🍄", "What to show in the navititle in the beginning, before the colon")
// flag.StringVar(&util.SiteName, "name", "wiki", "What is the name of your wiki")
// flag.StringVar(&util.UserHypha, "user-hypha", "u", "Hypha which is a superhypha of all user pages")
// flag.StringVar(&util.AuthMethod, "auth-method", "none", "What auth method to use. Variants: \"none\", \"fixed\"")
// flag.StringVar(&util.FixedCredentialsPath, "fixed-credentials-path", "mycocredentials.json", "Used when -auth-method=fixed. Path to file with user credentials.")
// flag.StringVar(&util.HeaderLinksHypha, "header-links-hypha", "", "Optional hypha that overrides the header links")
// flag.StringVar(&util.GeminiCertPath, "gemini-cert-path", "", "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini.")
flag . StringVar ( & util . ConfigFilePath , "config-path" , "" , "Path to a configuration file. Leave empty if you don't want to use it." )
2021-03-09 14:27:14 +00:00
flag . BoolVar ( & printExampleConfig , "print-example-config" , false , "If true, print an example configuration file contents and exit. You can save the output to a file and base your own configuration on it." )
flag . Usage = func ( ) {
fmt . Fprintf (
flag . CommandLine . Output ( ) ,
assets . HelpMessage ( ) ,
os . Args [ 0 ] ,
)
flag . PrintDefaults ( )
}
2020-10-25 15:06:51 +00:00
}
// Do the things related to cli args and die maybe
func parseCliArgs ( ) {
flag . Parse ( )
args := flag . Args ( )
2021-03-09 14:27:14 +00:00
if printExampleConfig {
fmt . Printf ( assets . ExampleConfig ( ) )
os . Exit ( 0 )
}
2020-10-25 15:06:51 +00:00
if len ( args ) == 0 {
log . Fatal ( "Error: pass a wiki directory" )
}
2021-03-09 14:27:14 +00:00
// It is ok if the path is ""
util . ReadConfigFile ( util . ConfigFilePath )
2021-03-06 09:40:47 +00:00
2020-10-25 15:06:51 +00:00
var err error
WikiDir , err = filepath . Abs ( args [ 0 ] )
util . WikiDir = WikiDir
if err != nil {
log . Fatal ( err )
}
2021-03-06 09:40:47 +00:00
if util . URL == "" {
2020-12-08 15:15:32 +00:00
util . URL = "http://0.0.0.0:" + util . ServerPort
}
2021-02-17 18:41:35 +00:00
util . HomePage = util . CanonicalName ( util . HomePage )
util . UserHypha = util . CanonicalName ( util . UserHypha )
util . HeaderLinksHypha = util . CanonicalName ( util . HeaderLinksHypha )
2021-03-06 09:40:47 +00:00
user . AuthUsed = util . UseFixedAuth
2021-03-07 14:58:37 +00:00
if user . AuthUsed && util . FixedCredentialsPath != "" {
user . ReadUsersFromFilesystem ( )
}
2020-10-25 15:06:51 +00:00
}