Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
iret-kawashima committed Nov 30, 2023
1 parent 27540b9 commit ba84773
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 218 deletions.
212 changes: 106 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Support

- Markdown table format
- Backlog table format
- Group rows based on first column value
- Group rows based on previous field value
- Color rows based on first column value
- Ignore specified columns

Notes
-----

- Only non-nested struct slices are accepted
- Only non-nested struct slices are accepted (but byte slices are converted to strings)
- Using reflect

Usage
Expand Down Expand Up @@ -57,163 +57,163 @@ func main() {
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/
/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/

table = mintab.NewTable(mintab.WithFormat(mintab.BacklogFormat))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName | CidrBlock |h
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16&br;0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16&br;0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/
/*
| InstanceName | SecurityGroupName | CidrBlock |h
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16&br;0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16&br;0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16&br;0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/

table = mintab.NewTable(mintab.WithHeader(false))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/
/*
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/

table = mintab.NewTable(mintab.WithEmptyFieldPlaceholder("NULL"))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | NULL | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | NULL |
*/
/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | NULL | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | NULL |
*/

table = mintab.NewTable(mintab.WithWordDelimiter(","))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | --------------------- |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16,0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16,0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16,0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16,0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16,0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/
/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | --------------------- |
| i-1 | sg-1 | 10.0.0.0/16 |
| i-1 | sg-1 | 10.1.0.0/16 |
| i-1 | sg-2 | 10.2.0.0/16 |
| i-1 | sg-2 | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16,0.0.0.0/0 |
| i-2 | sg-1 | 10.1.0.0/16,0.0.0.0/0 |
| i-2 | sg-2 | 10.2.0.0/16,0.0.0.0/0 |
| i-2 | sg-2 | 10.3.0.0/16,0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16,0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/

table = mintab.NewTable(mintab.WithMergeFields([]int{0, 1}), mintab.WithTheme(mintab.DarkTheme))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| | | 10.1.0.0/16 |
| | sg-2 | 10.2.0.0/16 |
| | | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| | | 10.1.0.0/16<br>0.0.0.0/0 |
| | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| | | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/
/*
| InstanceName | SecurityGroupName | CidrBlock |
| ------------ | ----------------- | ------------------------ |
| i-1 | sg-1 | 10.0.0.0/16 |
| | | 10.1.0.0/16 |
| | sg-2 | 10.2.0.0/16 |
| | | 10.3.0.0/16 |
| i-2 | sg-1 | 10.0.0.0/16<br>0.0.0.0/0 |
| | | 10.1.0.0/16<br>0.0.0.0/0 |
| | sg-2 | 10.2.0.0/16<br>0.0.0.0/0 |
| | | 10.3.0.0/16<br>0.0.0.0/0 |
| i-3 | N/A | 10.0.0.0/16<br>0.0.0.0/0 |
| i-4 | sg-4 | N/A |
*/

table = mintab.NewTable(mintab.WithIgnoreFields([]int{2}))
if err := table.Load(samples); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| InstanceName | SecurityGroupName |
| ------------ | ----------------- |
| i-1 | sg-1 |
| i-1 | sg-1 |
| i-1 | sg-2 |
| i-1 | sg-2 |
| i-2 | sg-1 |
| i-2 | sg-1 |
| i-2 | sg-2 |
| i-2 | sg-2 |
| i-3 | N/A |
| i-4 | sg-4 |
*/
/*
| InstanceName | SecurityGroupName |
| ------------ | ----------------- |
| i-1 | sg-1 |
| i-1 | sg-1 |
| i-1 | sg-2 |
| i-1 | sg-2 |
| i-2 | sg-1 |
| i-2 | sg-1 |
| i-2 | sg-2 |
| i-2 | sg-2 |
| i-3 | N/A |
| i-4 | sg-4 |
*/

type escaped struct {
Domain string
}
escapes := []escaped{
{Domain: "*.example.com"}
}
{Domain: "*.example.com"},
}

table = mintab.NewTable(mintab.WithEscapeTargets([]string{"*"}))
if err := table.Load(escs); err != nil {
if err := table.Load(escapes); err != nil {
log.Fatal(err)
}
fmt.Println(table.Out())

/*
| Domain |
| -------------- |
| \*.example.com |
}
/*
/*
| Domain |
| -------------- |
| \*.example.com |
*/
}
```

Author
Expand Down
Loading

0 comments on commit ba84773

Please sign in to comment.