mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Implement CLI args
This commit is contained in:
parent
9173b54c91
commit
de8af13098
17
README.md
17
README.md
@ -2,9 +2,9 @@
|
|||||||
A wiki engine.
|
A wiki engine.
|
||||||
|
|
||||||
This is the development branch for version 0.10. Features planned for this version:
|
This is the development branch for version 0.10. Features planned for this version:
|
||||||
* [ ] New file structure
|
* [x] New file structure
|
||||||
* [ ] Mycomarkup
|
* [ ] Mycomarkup
|
||||||
* [ ] CLI options
|
* [x] CLI options
|
||||||
* [ ] CSS improvements
|
* [ ] CSS improvements
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
@ -17,6 +17,19 @@ make
|
|||||||
# * create an executable called `mycorrhiza`. Run it with path to your wiki.
|
# * create an executable called `mycorrhiza`. Run it with path to your wiki.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```
|
||||||
|
mycorrhiza [OPTIONS...] WIKI_PATH
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-home string
|
||||||
|
The home page (default "home")
|
||||||
|
-port string
|
||||||
|
Port to serve the wiki at (default "1737")
|
||||||
|
-title string
|
||||||
|
How to call your wiki in the navititle (default "🍄")
|
||||||
|
```
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* Edit pages through html forms
|
* Edit pages through html forms
|
||||||
* Responsive design
|
* Responsive design
|
||||||
|
36
flag.go
Normal file
36
flag.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.StringVar(&util.ServerPort, "port", "1737", "Port to serve the wiki at")
|
||||||
|
flag.StringVar(&util.HomePage, "home", "home", "The home page")
|
||||||
|
flag.StringVar(&util.SiteTitle, "title", "🍄", "How to call your wiki in the navititle")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isCanonicalName(util.HomePage) {
|
||||||
|
log.Fatal("Error: you must use a proper name for the homepage")
|
||||||
|
}
|
||||||
|
}
|
12
main.go
12
main.go
@ -101,13 +101,7 @@ func handlerRecentChanges(w http.ResponseWriter, rq *http.Request) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Running MycorrhizaWiki β")
|
log.Println("Running MycorrhizaWiki β")
|
||||||
|
parseCliArgs()
|
||||||
var err error
|
|
||||||
WikiDir, err = filepath.Abs(os.Args[1])
|
|
||||||
util.WikiDir = WikiDir
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := os.Chdir(WikiDir); err != nil {
|
if err := os.Chdir(WikiDir); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -129,7 +123,7 @@ func main() {
|
|||||||
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
http.ServeFile(w, rq, WikiDir+"/static/favicon.ico")
|
||||||
})
|
})
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, rq *http.Request) {
|
||||||
http.Redirect(w, rq, "/page/home", http.StatusSeeOther)
|
http.Redirect(w, rq, "/page/"+util.HomePage, http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
log.Fatal(http.ListenAndServe("0.0.0.0:1737", nil))
|
log.Fatal(http.ListenAndServe("0.0.0.0:"+util.ServerPort, nil))
|
||||||
}
|
}
|
||||||
|
9
name.go
9
name.go
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bouncepaw/mycorrhiza/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// isCanonicalName checks if the `name` is canonical.
|
// isCanonicalName checks if the `name` is canonical.
|
||||||
@ -17,16 +19,17 @@ func CanonicalName(name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// naviTitle turns `canonicalName` into html string with each hypha path parts higlighted as links.
|
// naviTitle turns `canonicalName` into html string with each hypha path parts higlighted as links.
|
||||||
|
// TODO: rework as a template
|
||||||
func naviTitle(canonicalName string) string {
|
func naviTitle(canonicalName string) string {
|
||||||
var (
|
var (
|
||||||
html = `<h1 class="navi-title" id="0">
|
html = fmt.Sprintf(`<h1 class="navi-title" id="navi-title">
|
||||||
<a href="/">🍄</a>`
|
<a href="/page/%s">%s</a>`, util.HomePage, util.SiteTitle)
|
||||||
prevAcc = `/page/`
|
prevAcc = `/page/`
|
||||||
parts = strings.Split(canonicalName, "/")
|
parts = strings.Split(canonicalName, "/")
|
||||||
)
|
)
|
||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
html += fmt.Sprintf(`
|
html += fmt.Sprintf(`
|
||||||
<span>/</span>
|
<span aria-hidden="true">/</span>
|
||||||
<a href="%s">%s</a>`,
|
<a href="%s">%s</a>`,
|
||||||
prevAcc+part,
|
prevAcc+part,
|
||||||
strings.Title(part))
|
strings.Title(part))
|
||||||
|
@ -5,7 +5,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var WikiDir string
|
var (
|
||||||
|
ServerPort string
|
||||||
|
HomePage string
|
||||||
|
SiteTitle string
|
||||||
|
WikiDir string
|
||||||
|
)
|
||||||
|
|
||||||
// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir.
|
// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir.
|
||||||
func ShorterPath(path string) string {
|
func ShorterPath(path string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user