mirror of
https://github.com/cheat/cheat.git
synced 2024-10-31 21:21:02 +01:00
80c91cbdee
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
50 lines
847 B
Go
50 lines
847 B
Go
package ssh_config
|
|
|
|
import "fmt"
|
|
|
|
type token struct {
|
|
Position
|
|
typ tokenType
|
|
val string
|
|
}
|
|
|
|
func (t token) String() string {
|
|
switch t.typ {
|
|
case tokenEOF:
|
|
return "EOF"
|
|
}
|
|
return fmt.Sprintf("%q", t.val)
|
|
}
|
|
|
|
type tokenType int
|
|
|
|
const (
|
|
eof = -(iota + 1)
|
|
)
|
|
|
|
const (
|
|
tokenError tokenType = iota
|
|
tokenEOF
|
|
tokenEmptyLine
|
|
tokenComment
|
|
tokenKey
|
|
tokenEquals
|
|
tokenString
|
|
)
|
|
|
|
func isSpace(r rune) bool {
|
|
return r == ' ' || r == '\t'
|
|
}
|
|
|
|
func isKeyStartChar(r rune) bool {
|
|
return !(isSpace(r) || r == '\r' || r == '\n' || r == eof)
|
|
}
|
|
|
|
// I'm not sure that this is correct
|
|
func isKeyChar(r rune) bool {
|
|
// Keys start with the first character that isn't whitespace or [ and end
|
|
// with the last non-whitespace character before the equals sign. Keys
|
|
// cannot contain a # character."
|
|
return !(r == '\r' || r == '\n' || r == eof || r == '=')
|
|
}
|