urloli/main.go

65 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"os"
"strconv"
)
var version = "2.2.0"
func help () {
fmt.Println(" URLロリ - クッソ小さいURL短縮作成ソフトだわ〜♡")
fmt.Println("https://urlo.li/ | https://gitler.moe/suwako/urloli")
fmt.Println("")
fmt.Println("使い方:");
fmt.Println("urloli -v :バージョンを表示");
fmt.Println("urloli -s [ポート番号] ポート番号でウェブサーバーを実行デフォルト9910");
fmt.Println("urloli -h :ヘルプを表示");
fmt.Println("urloli <URL> コマンドラインでURLを短縮");
}
func main () {
cnf, err := getconf()
if err != nil {
fmt.Println(err)
return
}
args := os.Args
if len(args) == 2 {
if args[1] == "-v" {
fmt.Println("urloli-" + version)
return
} else if args[1] == "-s" {
serv(cnf, 9910)
} else if args[1] == "-h" {
help()
return
} else {
if checkprefix(args[1]) {
_, key := geturl(args[1], cnf.linkpath, true)
if (key != "") {
fmt.Println(cnf.domain + "/" + key)
} else {
fmt.Println(cnf.domain + "/" + insertjson(args[1], cnf.linkpath))
}
return
} else {
fmt.Println("URLは不正です。終了…")
return
}
}
} else if len(args) == 3 && args[1] == "-s" {
if port, err := strconv.Atoi(args[2]); err != nil {
fmt.Printf("%qは数字ではありません。\n", args[2])
return
} else {
serv(cnf, port)
}
} else {
help()
return
}
}