Skip to content

Commit

Permalink
[BUGFIX] Fix line indexes in splicer and parser
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
lthurston committed Nov 15, 2015
1 parent 1a5d09b commit e9d8f0d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
quiet.iml
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ editing, copying, exporting (to share with others).
2) Set up a go dev environment: `mkdir -p ~/go/{src,bin}`

3) Add some stuff to your .bash_profile:

Your GOROOT is probably not in the same place as mine.

```
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export GOROOT=/opt/boxen/homebrew/Cellar/go/1.5.1/libexec
export PATH=$PATH:$GOBIN
```

Expand Down Expand Up @@ -75,16 +79,16 @@ Available Flags:
Use "quiet help [command]" for more information about that command.
```

The -f/--from setting can also come from .quiet configuration as new.from. The
The -f / --from setting can also come from .quiet configuration as new.from. The
value should be an existing hostname or a template that you've created for
purpose of providing common defaults.

-s/--skip-interactive will skip the interactive modification of values from the
-s / --skip-interactive will skip the interactive modification of values from the
copied configuration snippet, making new behave more like a copy action.

-n/--name allows the name of the new host to be specified in the command.
-n / --name allows the name of the new host to be specified in the command.

-o/--stdout will output the new snippet rather than writing to the ssh config
-o / --stdout will output the new snippet rather than writing to the ssh config
file.

**Examples**
Expand Down
5 changes: 1 addition & 4 deletions commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ var rmCmd = &cobra.Command{

defer f.Close()

// TODO: Splicer line numbering is weird. Ideally, we'd put the
// StartLine() as the splice from and EndLine() as splice too, any everything
// would taste like candy canes.
splicer.SpliceInto(host.StartLine() - 1, host.EndLine(), "", f, &buffer)
splicer.SpliceInto(host.StartLine(), host.EndLine(), "", f, &buffer)
writer.Replace(buffer.String())
} else {
fmt.Println("Couldn't find host or empty: \"" + args[0] + "\"")
Expand Down
2 changes: 1 addition & 1 deletion host/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func fromScanner(hosts *HostsCollection, s *bufio.Scanner) {

host := MakeHostPosition()
for s.Scan() {
lineIndex++
line := s.Text()
if !skippableLine(line) {
if hostLine(line) {
Expand All @@ -46,6 +45,7 @@ func fromScanner(hosts *HostsCollection, s *bufio.Scanner) {
}
lastNonSkippableLine = lineIndex
}
lineIndex++
}

if foundFirstHostLine {
Expand Down
46 changes: 32 additions & 14 deletions host/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Host junkfood
if count := hosts.Count(); count != 1 {
t.Errorf("Expecting 1 hosts in this config; got %v", count)
}
if hosts.GetIndex(0).StartLine() != 2 {
t.Errorf("Expecting first host to begin on line 2; got %v", hosts.GetIndex(0).StartLine())
if hosts.GetIndex(0).StartLine() != 1 {
t.Errorf("Expecting first host to begin on line 1; got %v", hosts.GetIndex(0).StartLine())
}
if hosts.GetIndex(0).EndLine() != 8 {
t.Errorf("Expecting first host to end on line 8; got %v", hosts.GetIndex(0).EndLine())
if hosts.GetIndex(0).EndLine() != 7 {
t.Errorf("Expecting first host to end on line 7; got %v", hosts.GetIndex(0).EndLine())
}
}

Expand Down Expand Up @@ -76,24 +76,42 @@ Host ormulex-qa
User monkey
ProxyCommand ssh cmw3wbq10 'nc %h %banana %p'
#2A
#1A
#0A
Host fraceass
Hostname fesces.org
User blah blah woof woof
Identidfysdfjkh dsf
IdentityFile test
IdentityFile blah blah
#0B
#1B
#2B
# A comment with some empty lines around it
`)
if count := hosts.Count(); count != 2 {
t.Errorf("Expecting 2 hosts in this config; got %v", count)
if count := hosts.Count(); count != 3 {
t.Errorf("Expecting 3 hosts in this config; got %v", count)
}
if hosts.GetIndex(0).StartLine() != 13 {
t.Errorf("Expecting first host to begin on line 13; got %v", hosts.GetIndex(0).StartLine())
if hosts.GetIndex(0).StartLine() != 12 {
t.Errorf("Expecting first host to begin on line 12; got %v", hosts.GetIndex(0).StartLine())
}
if hosts.GetIndex(0).EndLine() != 16 {
t.Errorf("Expecting first host to end on line 16; got %v", hosts.GetIndex(0).EndLine())
if hosts.GetIndex(0).EndLine() != 15 {
t.Errorf("Expecting first host to end on line 15; got %v", hosts.GetIndex(0).EndLine())
}
if hosts.GetIndex(1).StartLine() != 18 {
t.Errorf("Expecting second host to begin on line 18; got %v", hosts.GetIndex(1).StartLine())
if hosts.GetIndex(1).StartLine() != 17 {
t.Errorf("Expecting second host to begin on line 17; got %v", hosts.GetIndex(1).StartLine())
}
if hosts.GetIndex(1).EndLine() != 21 {
t.Errorf("Expecting second host to end on line 21; got %v", hosts.GetIndex(1).EndLine())
if hosts.GetIndex(1).EndLine() != 20 {
t.Errorf("Expecting second host to end on line 20; got %v", hosts.GetIndex(1).EndLine())
}
if hosts.GetIndex(2).StartLine() != 25 {
t.Errorf("Expecting second host to begin on line 25; got %v", hosts.GetIndex(1).StartLine())
}
if hosts.GetIndex(2).EndLine() != 30 {
t.Errorf("Expecting second host to end on line 30; got %v", hosts.GetIndex(1).EndLine())
}
}

Expand Down

0 comments on commit e9d8f0d

Please sign in to comment.