2020-10-25 15:06:51 +00:00
package main
import (
"flag"
"log"
"path/filepath"
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"
)
func init ( ) {
2020-12-17 12:59:59 +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" )
2020-12-08 15:15:32 +00:00
flag . StringVar ( & util . ServerPort , "port" , "1737" , "Port to serve the wiki at using HTTP" )
flag . StringVar ( & util . HomePage , "home" , "home" , "The home page name" )
2021-01-23 13:45:17 +00:00
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" )
2021-01-23 16:37:29 +00:00
flag . StringVar ( & util . UserHypha , "user-hypha" , "u" , "Hypha which is a superhypha of all user pages" )
2020-11-13 18:45:42 +00:00
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." )
2021-01-23 19:00:58 +00:00
flag . StringVar ( & util . HeaderLinksHypha , "header-links-hypha" , "" , "Optional hypha that overrides the header links" )
2021-02-09 14:35:02 +00:00
flag . StringVar ( & util . GeminiCertPath , "gemini-cert-path" , "" , "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini." )
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 ( )
if len ( args ) == 0 {
log . Fatal ( "Error: pass a wiki directory" )
}
var err error
WikiDir , err = filepath . Abs ( args [ 0 ] )
util . WikiDir = WikiDir
if err != nil {
log . Fatal ( err )
}
2020-12-08 15:15:32 +00:00
if util . URL == "http://0.0.0.0:$port" {
util . URL = "http://0.0.0.0:" + util . ServerPort
}
2021-01-23 19:00:58 +00:00
util . HomePage = CanonicalName ( util . HomePage )
util . UserHypha = CanonicalName ( util . UserHypha )
util . HeaderLinksHypha = CanonicalName ( util . HeaderLinksHypha )
2020-11-13 18:45:42 +00:00
switch util . AuthMethod {
case "none" :
case "fixed" :
user . AuthUsed = true
2021-01-09 20:49:48 +00:00
user . ReadUsersFromFilesystem ( )
2020-11-13 18:45:42 +00:00
default :
log . Fatal ( "Error: unknown auth method:" , util . AuthMethod )
}
2020-10-25 15:06:51 +00:00
}