https://github.com/harakeishi/gscp
gscp is the ssh-config parser available in go. gscp is named as an abbreviation of go ssh config parser.
https://github.com/harakeishi/gscp
go golang parser ssh ssh-config
Last synced: 6 months ago
JSON representation
gscp is the ssh-config parser available in go. gscp is named as an abbreviation of go ssh config parser.
- Host: GitHub
- URL: https://github.com/harakeishi/gscp
- Owner: harakeishi
- License: mit
- Created: 2022-12-18T12:11:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T06:54:28.000Z (over 3 years ago)
- Last Synced: 2025-12-24T18:02:42.787Z (6 months ago)
- Topics: go, golang, parser, ssh, ssh-config
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gscp
`gscp` is the ssh-config parser available in go.
`gscp` is named as an abbreviation of `go ssh config parser`.
## Importing
```go
import (
"github.com/harakeishi/gscp"
)
```
## Documentation
Visit the docs on [GoDoc](https://pkg.go.dev/github.com/harakeishi/gscp)
## usage
If no arguments are passed to `LoadConfig()`, `~/.ssh/config` will be read.
```go
package main
import (
"fmt"
"github.com/harakeishi/gscp"
)
func main() {
// Reads a config file and gets it as a string
s, _ := gscp.LoadConfig()
// parse
r, _ := gscp.Parse(s)
fmt.Printf("%+v", r)
}
```
```sh
$ go run ./cmd/main.go
[{Name:testhost Options:[{Name:HostName Value:192.0.2.1} {Name:User Value:myuser} {Name:IdentityFile Value:~/.ssh/id_rsa} {Name:ServerAliveInterval Value:60}]}]
```
If you want to parse a config in a specific directory, pass the path as follows.
```go
package main
import (
"fmt"
"github.com/harakeishi/gscp"
)
func main() {
// Reads a config file and gets it as a string
path := gscp.Path("./testData/test1_config")
s, _ := gscp.LoadConfig(path)
// parse
fmt.Println(gscp.Parse(s))
}
```
Obtains information on the specified host and the specified options.
```go
package main
import (
"fmt"
"github.com/harakeishi/gscp"
)
func main() {
// Specify path
path := gscp.Path("./testData/test1_config")
// Load config.
s, _ := gscp.LoadConfig(path)
// Parse config.
hosts, _ := gscp.Parse(s)
// Obtain information on the specified host
host := hosts.FindHost("testhost")
fmt.Printf("%+v\n", host)
// Obtain information on specified options
hostname := host.FindOption("HostName").Value
fmt.Printf("%+v\n", hostname)
}
```
```sh
PS C:\src\smp> go run .\cmd\main.go
{Name:testhost Options:[{Name:HostName Value:192.0.2.1} {Name:User Value:myuser} {Name:IdentityFile Value:~/.ssh/id_rsa} {Name:ServerAliveInterval Value:60}]}
192.0.2.1
```
## License
Copyright (c) 2023 harakeishi
Licensed under [MIT](LICENSE)