Compare commits

...

1 Commits

Author SHA1 Message Date
Roy Han
c494aea5c8 Strip stop strings 2024-06-20 09:06:08 -07:00

View File

@ -636,7 +636,7 @@ func ShowHandler(cmd *cobra.Command, args []string) error {
case "modelfile": case "modelfile":
fmt.Println(resp.Modelfile) fmt.Println(resp.Modelfile)
case "parameters": case "parameters":
fmt.Println(resp.Parameters) fmt.Println(formatParams(resp.Parameters, false))
case "system": case "system":
fmt.Println(resp.System) fmt.Println(resp.System)
case "template": case "template":
@ -664,7 +664,7 @@ func ShowHandler(cmd *cobra.Command, args []string) error {
mainTableData := [][]string{ mainTableData := [][]string{
{"Model"}, {"Model"},
{renderSubTable(modelData, false)}, {renderSubTable(modelData, false, true)},
} }
if resp.ProjectorInfo != nil { if resp.ProjectorInfo != nil {
@ -678,20 +678,20 @@ func ShowHandler(cmd *cobra.Command, args []string) error {
mainTableData = append(mainTableData, mainTableData = append(mainTableData,
[]string{"Projector"}, []string{"Projector"},
[]string{renderSubTable(projectorData, false)}, []string{renderSubTable(projectorData, false, true)},
) )
} }
if resp.Parameters != "" { if resp.Parameters != "" {
mainTableData = append(mainTableData, []string{"Parameters"}, []string{formatParams(resp.Parameters)}) mainTableData = append(mainTableData, []string{"Parameters"}, []string{formatParams(resp.Parameters, true)})
} }
if resp.System != "" { if resp.System != "" {
mainTableData = append(mainTableData, []string{"System"}, []string{renderSubTable(twoLines(resp.System), true)}) mainTableData = append(mainTableData, []string{"System"}, []string{renderSubTable(twoLines(resp.System), true, true)})
} }
if resp.License != "" { if resp.License != "" {
mainTableData = append(mainTableData, []string{"License"}, []string{renderSubTable(twoLines(resp.License), true)}) mainTableData = append(mainTableData, []string{"License"}, []string{renderSubTable(twoLines(resp.License), true, true)})
} }
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
@ -708,7 +708,7 @@ func ShowHandler(cmd *cobra.Command, args []string) error {
return nil return nil
} }
func renderSubTable(data [][]string, file bool) string { func renderSubTable(data [][]string, file bool, tab bool) string {
var buf bytes.Buffer var buf bytes.Buffer
table := tablewriter.NewWriter(&buf) table := tablewriter.NewWriter(&buf)
table.SetAutoWrapText(!file) table.SetAutoWrapText(!file)
@ -723,6 +723,10 @@ func renderSubTable(data [][]string, file bool) string {
table.Render() table.Render()
if !tab {
return buf.String()
}
renderedTable := buf.String() renderedTable := buf.String()
lines := strings.Split(renderedTable, "\n") lines := strings.Split(renderedTable, "\n")
for i, line := range lines { for i, line := range lines {
@ -750,14 +754,16 @@ func twoLines(s string) [][]string {
return res return res
} }
func formatParams(s string) string { func formatParams(s string, tab bool) string {
lines := strings.Split(s, "\n") lines := strings.Split(s, "\n")
table := [][]string{} table := [][]string{}
for _, line := range lines { for _, line := range lines {
table = append(table, strings.Fields(line)) fields := strings.Fields(line)
fields[1] = strings.TrimPrefix(strings.TrimSuffix(fields[1], `"`), `"`)
table = append(table, fields)
} }
return renderSubTable(table, false) return renderSubTable(table, false, tab)
} }
func CopyHandler(cmd *cobra.Command, args []string) error { func CopyHandler(cmd *cobra.Command, args []string) error {