Skip to content

Commit

Permalink
move UnquoteString to output_filter.go
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Jul 16, 2024
1 parent ff159b0 commit f4544a3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
7 changes: 0 additions & 7 deletions cli/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,3 @@ func SplitStringWithPrefix(s string, splitters string) (string, string, bool) {
return s[:i], s[i+1:], true

}

func UnquoteString(s string) string {
if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") && len(s) >= 2 {
return s[1 : len(s)-1]
}
return s
}
7 changes: 0 additions & 7 deletions cli/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (tc *testContext) detectFlag(name string) (*Flag, error) {
return f, nil
}
return nil, fmt.Errorf("unknown flag --%s", name)

}

func (tc *testContext) detectFlagByShorthand(ch rune) (*Flag, error) {
Expand All @@ -39,7 +38,6 @@ func (tc *testContext) detectFlagByShorthand(ch rune) (*Flag, error) {
return f, nil
}
return nil, fmt.Errorf("unknown flag -%c", ch)

}

func newTestContext() *testContext {
Expand Down Expand Up @@ -120,8 +118,3 @@ func TestParser3(t *testing.T) {
assert.Equal(t, "s1", s)
assert.NotNil(t, fs.Get("prev"))
}

func TestUnquoteString(t *testing.T) {
str := UnquoteString(`"nicai"`)
assert.Equal(t, "nicai", str)
}
9 changes: 8 additions & 1 deletion openapi/output_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (a *TableOutputFilter) FilterOutput(s string) (string, error) {

var colNames []string
if v, ok := OutputFlag(a.ctx.Flags()).GetFieldValue("cols"); ok {
v = cli.UnquoteString(v)
v = UnquoteString(v)
colNames = strings.Split(v, ",")
} else {
return s, fmt.Errorf("you need to assign col=col1,col2,... with --output")
Expand Down Expand Up @@ -158,3 +158,10 @@ func toIntfArray(stringArray []string) []interface{} {
}
return intfArray
}

func UnquoteString(s string) string {
if strings.HasPrefix(s, "\"") && strings.HasSuffix(s, "\"") && len(s) >= 2 {
return s[1 : len(s)-1]
}
return s
}
7 changes: 6 additions & 1 deletion openapi/output_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -105,3 +105,8 @@ func TestTableOutputFilter_FormatTable(t *testing.T) {
assert.Equal(t, "Num | name | type | api\n--- | ---- | ---- | ---\n0 | <nil> | <nil> | <nil>\n1 | <nil> | <nil> | <nil>\n", str)
assert.Nil(t, err)
}

func TestUnquoteString(t *testing.T) {
str := UnquoteString(`"nicai"`)
assert.Equal(t, "nicai", str)
}

0 comments on commit f4544a3

Please sign in to comment.