2020-10-25 15:06:51 +00:00
package main
import (
"flag"
2021-03-09 14:27:14 +00:00
"fmt"
2021-05-09 09:36:39 +00:00
"github.com/bouncepaw/mycorrhiza/cfg"
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-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-05-09 09:36:39 +00:00
flag . StringVar ( & cfg . 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-05-09 10:42:12 +00:00
wikiDir , err := filepath . Abs ( args [ 0 ] )
cfg . WikiDir = wikiDir
2020-10-25 15:06:51 +00:00
if err != nil {
log . Fatal ( err )
}
2021-05-09 09:36:39 +00:00
if cfg . URL == "" {
cfg . URL = "http://0.0.0.0:" + cfg . HTTPPort
2020-12-08 15:15:32 +00:00
}
2021-05-09 09:36:39 +00:00
cfg . HomeHypha = util . CanonicalName ( cfg . HomeHypha )
cfg . UserHypha = util . CanonicalName ( cfg . UserHypha )
cfg . HeaderLinksHypha = util . CanonicalName ( cfg . HeaderLinksHypha )
2020-10-25 15:06:51 +00:00
}