-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,379 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package format | ||
|
||
import ( | ||
"flag" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var Indent = " " | ||
|
||
type Options struct { | ||
// Do not print reformatted sources to standard output. | ||
// If a file's formatting is different from thriftls's, overwrite it | ||
// with thrfitls's version. | ||
Write bool `yaml:"rewrite"` | ||
|
||
// Indent to use. Support: nspace(s), ntab(s). example: 4spaces, 1tab, tab | ||
// if indent format is invalid or not specified, default is 4spaces | ||
Indent string `yaml:"indent"` | ||
|
||
// Do not print reformatted sources to standard output. | ||
// If a file's formatting is different than gofmt's, print diffs | ||
// to standard output. | ||
Diff bool `yaml:"Diff"` | ||
} | ||
|
||
func (o *Options) SetFlags() { | ||
flag.BoolVar(&o.Write, "w", false, "Do not print reformatted sources to standard output. If a file's formatting is different from thriftls's, overwrite it with thrfitls's version.") | ||
flag.BoolVar(&o.Diff, "d", false, "Do not print reformatted sources to standard output. If a file's formatting is different than gofmt's, print diffs to standard output.") | ||
flag.StringVar(&o.Indent, "indent", "4spaces", "Indent to use. Support: num*space, num*tab. example: 4spaces, 1tab, tab") | ||
} | ||
|
||
func (o *Options) InitDefaultIndent() { | ||
Indent = o.GetIndent() | ||
} | ||
|
||
func (o *Options) GetIndent() string { | ||
if o.Indent == "" { | ||
o.Indent = "4spaces" | ||
} | ||
|
||
indent := o.Indent | ||
suffixes := []string{"spaces", "space", "tabs", "tab"} | ||
for _, suffix := range suffixes { | ||
if strings.HasSuffix(indent, suffix) { | ||
char := "" | ||
if strings.HasPrefix(suffix, "tab") { | ||
char = " " | ||
} else { | ||
char = " " | ||
} | ||
num := 1 | ||
numStr := strings.TrimSuffix(indent, suffix) | ||
if len(numStr) == 0 { | ||
num = 1 | ||
} else { | ||
num, _ = strconv.Atoi(numStr) | ||
if num == 0 { | ||
num = 4 | ||
char = " " | ||
} | ||
} | ||
|
||
return strings.Repeat(char, num) | ||
} | ||
} | ||
|
||
return " " | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package format | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOptions_GetIndent(t *testing.T) { | ||
type fields struct { | ||
Write bool | ||
Indent string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
{ | ||
name: "4spaces", | ||
fields: fields{ | ||
Indent: "4spaces", | ||
}, | ||
want: " ", | ||
}, | ||
{ | ||
name: "1space", | ||
fields: fields{ | ||
Indent: "1spaces", | ||
}, | ||
want: " ", | ||
}, | ||
{ | ||
name: "space", | ||
fields: fields{ | ||
Indent: "space", | ||
}, | ||
want: " ", | ||
}, | ||
{ | ||
name: "2tabs", | ||
fields: fields{ | ||
Indent: "2tabs", | ||
}, | ||
want: "\t\t", | ||
}, | ||
{ | ||
name: "1tab", | ||
fields: fields{ | ||
Indent: "1tab", | ||
}, | ||
want: "\t", | ||
}, | ||
{ | ||
name: "tab", | ||
fields: fields{ | ||
Indent: "tab", | ||
}, | ||
want: "\t", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
o := &Options{ | ||
Write: tt.fields.Write, | ||
Indent: tt.fields.Indent, | ||
} | ||
assert.Equal(t, tt.want, o.GetIndent()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RSFile格式定义 | ||
============ | ||
|
||
RSFile(Record Sequence File)是基于记录的顺序文件。其基础文件格式定义了一个 | ||
二进制记录的序列,然后在此基础上定义了上层服务的专有文件格式(如结构化存储表文件)。 | ||
|
||
文件格式定义参考io/RSFile.thrift和sds/SLFile.thrift。 |
Oops, something went wrong.