-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.go
42 lines (36 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package lemon
import (
"fmt"
"regexp"
"strings"
)
var Version string
var Usage = fmt.Sprintf(`Usage: lemonade [options]... SUB_COMMAND [arg]
Sub Commands:
open [URL] Open URL by browser
copy [text] Copy text.
paste Paste text.
server Start lemonade server.
Options:
--port=2489 TCP port number
--line-ending Convert Line Ending(CR/CRLF)
--allow="0.0.0.0/0,::/0" Allow IP Range [Server only]
--host="localhost" Destination hostname [Client only]
--trans-loopback=true Translate loopback address [open subcommand only]
--trans-localfile=true Translate local file path [open subcommand only]
--help Show this message
Version:
%s`, Version)
func ConvertLineEnding(text, option string) string {
switch option {
case "lf", "LF":
text = strings.Replace(text, "\r\n", "\n", -1)
return strings.Replace(text, "\r", "\n", -1)
case "crlf", "CRLF":
text = regexp.MustCompile(`\r(.)|\r$`).ReplaceAllString(text, "\r\n$1")
text = regexp.MustCompile(`([^\r])\n|^\n`).ReplaceAllString(text, "$1\r\n")
return text
default:
return text
}
}