diff --git a/components/mdz/pkg/cmd/account/create.go b/components/mdz/pkg/cmd/account/create.go index e936dda8..1bae78d6 100644 --- a/components/mdz/pkg/cmd/account/create.go +++ b/components/mdz/pkg/cmd/account/create.go @@ -3,7 +3,6 @@ package account import ( "encoding/json" "errors" - "fmt" "strconv" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" @@ -92,8 +91,7 @@ func (f *factoryAccountCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Account ID %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Account", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/account/create_test.go b/components/mdz/pkg/cmd/account/create_test.go index 5571d80f..d3c268d0 100644 --- a/components/mdz/pkg/cmd/account/create_test.go +++ b/components/mdz/pkg/cmd/account/create_test.go @@ -2,9 +2,10 @@ package account import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -92,5 +93,5 @@ func Test_newCmdAccountCreate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Account ID 01933f96-ed04-7c57-be5b-c091388830f8 has been successfully created") + assert.Contains(t, output, "The Account 01933f96-ed04-7c57-be5b-c091388830f8 has been successfully created.") } diff --git a/components/mdz/pkg/cmd/account/delete.go b/components/mdz/pkg/cmd/account/delete.go index 389dfbb7..98d5b55e 100644 --- a/components/mdz/pkg/cmd/account/delete.go +++ b/components/mdz/pkg/cmd/account/delete.go @@ -1,8 +1,6 @@ package account import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -73,8 +71,7 @@ func (f *factoryAccountDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Account ID %s has been successfully deleted.", f.AccountID)) + output.FormatAndPrint(f.factory, f.AccountID, "Account", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/account/delete_test.go b/components/mdz/pkg/cmd/account/delete_test.go index a76d4891..2dd55999 100644 --- a/components/mdz/pkg/cmd/account/delete_test.go +++ b/components/mdz/pkg/cmd/account/delete_test.go @@ -2,9 +2,10 @@ package account import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -43,5 +44,5 @@ func Test_newCmdAccountDelete(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Account ID 444 has been successfully deleted.") + assert.Contains(t, output, "The Account 444 has been successfully deleted.") } diff --git a/components/mdz/pkg/cmd/account/describe.go b/components/mdz/pkg/cmd/account/describe.go index fd3f994f..6b163cf6 100644 --- a/components/mdz/pkg/cmd/account/describe.go +++ b/components/mdz/pkg/cmd/account/describe.go @@ -116,10 +116,12 @@ func (f *factoryAccountDescribe) outputAccount(cmd *cobra.Command, account *mmod func (f *factoryAccountDescribe) describePrint(account *mmodel.Account) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) tbl.AddRow("ID:", account.ID) diff --git a/components/mdz/pkg/cmd/account/list.go b/components/mdz/pkg/cmd/account/list.go index 29deaa29..b9958db7 100644 --- a/components/mdz/pkg/cmd/account/list.go +++ b/components/mdz/pkg/cmd/account/list.go @@ -70,9 +70,6 @@ func (f *factoryAccountList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "NAME", @@ -82,7 +79,12 @@ func (f *factoryAccountList) runE(cmd *cobra.Command, _ []string) error { "CREATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range accounts.Items { diff --git a/components/mdz/pkg/cmd/account/update.go b/components/mdz/pkg/cmd/account/update.go index 4de30b73..1a4ae394 100644 --- a/components/mdz/pkg/cmd/account/update.go +++ b/components/mdz/pkg/cmd/account/update.go @@ -3,7 +3,6 @@ package account import ( "encoding/json" "errors" - "fmt" "strconv" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" @@ -106,8 +105,7 @@ func (f *factoryAccountUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Account ID %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Account", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/account/update_test.go b/components/mdz/pkg/cmd/account/update_test.go index e5df08ad..a20982ec 100644 --- a/components/mdz/pkg/cmd/account/update_test.go +++ b/components/mdz/pkg/cmd/account/update_test.go @@ -2,16 +2,16 @@ package account import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "github.com/stretchr/testify/assert" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" "github.com/LerianStudio/midaz/components/mdz/pkg/ptr" "github.com/LerianStudio/midaz/pkg/mmodel" - - "github.com/stretchr/testify/assert" ) func Test_newCmdLedgerUpdate(t *testing.T) { @@ -71,5 +71,5 @@ func Test_newCmdLedgerUpdate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Account ID 777 has been successfully updated.") + assert.Contains(t, output, "The Account 777 has been successfully updated.") } diff --git a/components/mdz/pkg/cmd/asset/create.go b/components/mdz/pkg/cmd/asset/create.go index e325ecd3..84cf639f 100644 --- a/components/mdz/pkg/cmd/asset/create.go +++ b/components/mdz/pkg/cmd/asset/create.go @@ -3,7 +3,6 @@ package asset import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -76,8 +75,7 @@ func (f *factoryAssetCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Asset ID %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Asset", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/asset/create_test.go b/components/mdz/pkg/cmd/asset/create_test.go index 687f75ad..3ba18983 100644 --- a/components/mdz/pkg/cmd/asset/create_test.go +++ b/components/mdz/pkg/cmd/asset/create_test.go @@ -2,9 +2,10 @@ package asset import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -89,5 +90,5 @@ func Test_newCmdAssetCreate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Asset ID 01930219-2c25-7a37-a5b9-610d44ae0a27 has been successfully created") + assert.Contains(t, output, "The Asset 01930219-2c25-7a37-a5b9-610d44ae0a27 has been successfully created.") } diff --git a/components/mdz/pkg/cmd/asset/delete.go b/components/mdz/pkg/cmd/asset/delete.go index e7d4acc6..5f665721 100644 --- a/components/mdz/pkg/cmd/asset/delete.go +++ b/components/mdz/pkg/cmd/asset/delete.go @@ -1,8 +1,6 @@ package asset import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -63,8 +61,7 @@ func (f *factoryAssetDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Asset ID %s has been successfully deleted.", f.AssetID)) + output.FormatAndPrint(f.factory, f.AssetID, "Asset", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/asset/delete_test.go b/components/mdz/pkg/cmd/asset/delete_test.go index 3ef66a3e..bc940b28 100644 --- a/components/mdz/pkg/cmd/asset/delete_test.go +++ b/components/mdz/pkg/cmd/asset/delete_test.go @@ -2,9 +2,10 @@ package asset import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -42,5 +43,5 @@ func Test_newCmdAssetDelete(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Asset ID 444 has been successfully deleted.") + assert.Contains(t, output, "The Asset 444 has been successfully deleted.") } diff --git a/components/mdz/pkg/cmd/asset/describe.go b/components/mdz/pkg/cmd/asset/describe.go index e94d40d5..6006c009 100644 --- a/components/mdz/pkg/cmd/asset/describe.go +++ b/components/mdz/pkg/cmd/asset/describe.go @@ -106,10 +106,12 @@ func (f *factoryAssetDescribe) outputAsset(cmd *cobra.Command, asset *mmodel.Ass func (f *factoryAssetDescribe) describePrint(asset *mmodel.Asset) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) tbl.AddRow("ID:", asset.ID) diff --git a/components/mdz/pkg/cmd/asset/list.go b/components/mdz/pkg/cmd/asset/list.go index e70b9893..200f91bf 100644 --- a/components/mdz/pkg/cmd/asset/list.go +++ b/components/mdz/pkg/cmd/asset/list.go @@ -60,9 +60,6 @@ func (f *factoryAssetList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "NAME", @@ -73,7 +70,12 @@ func (f *factoryAssetList) runE(cmd *cobra.Command, _ []string) error { "CREATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range leds.Items { diff --git a/components/mdz/pkg/cmd/asset/update.go b/components/mdz/pkg/cmd/asset/update.go index 618976bd..be6f4419 100644 --- a/components/mdz/pkg/cmd/asset/update.go +++ b/components/mdz/pkg/cmd/asset/update.go @@ -3,7 +3,6 @@ package asset import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -91,8 +90,7 @@ func (f *factoryAssetUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Asset ID %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Asset", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/asset/update_test.go b/components/mdz/pkg/cmd/asset/update_test.go index 3a550344..9495604a 100644 --- a/components/mdz/pkg/cmd/asset/update_test.go +++ b/components/mdz/pkg/cmd/asset/update_test.go @@ -2,9 +2,10 @@ package asset import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -70,5 +71,5 @@ func Test_newCmdLedgerUpdate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Asset ID 412 has been successfully updated.") + assert.Contains(t, output, "The Asset 412 has been successfully updated.") } diff --git a/components/mdz/pkg/cmd/ledger/create.go b/components/mdz/pkg/cmd/ledger/create.go index 422e61ae..22e1a7bc 100644 --- a/components/mdz/pkg/cmd/ledger/create.go +++ b/components/mdz/pkg/cmd/ledger/create.go @@ -3,7 +3,6 @@ package ledger import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -63,8 +62,7 @@ func (f *factoryLedgerCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The ledger_id %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Ledger", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/ledger/create_test.go b/components/mdz/pkg/cmd/ledger/create_test.go index eb66f7f8..a5035adc 100644 --- a/components/mdz/pkg/cmd/ledger/create_test.go +++ b/components/mdz/pkg/cmd/ledger/create_test.go @@ -2,9 +2,10 @@ package ledger import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -76,6 +77,5 @@ func Test_newCmdLedgerCreate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The ledger_id 0192e251-328d-7390-99f5-5c54980115ed has been successfully created") - + assert.Contains(t, output, "The Ledger 0192e251-328d-7390-99f5-5c54980115ed has been successfully created.") } diff --git a/components/mdz/pkg/cmd/ledger/delete.go b/components/mdz/pkg/cmd/ledger/delete.go index 0fa35e3c..999bf5e9 100644 --- a/components/mdz/pkg/cmd/ledger/delete.go +++ b/components/mdz/pkg/cmd/ledger/delete.go @@ -1,8 +1,6 @@ package ledger import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -45,8 +43,7 @@ func (f *factoryLedgerDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Ledger %s has been successfully deleted.", f.ledgerID)) + output.FormatAndPrint(f.factory, f.ledgerID, "Ledger", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/ledger/delete_test.go b/components/mdz/pkg/cmd/ledger/delete_test.go index 466de146..91aa0ca2 100644 --- a/components/mdz/pkg/cmd/ledger/delete_test.go +++ b/components/mdz/pkg/cmd/ledger/delete_test.go @@ -2,9 +2,10 @@ package ledger import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" diff --git a/components/mdz/pkg/cmd/ledger/describe.go b/components/mdz/pkg/cmd/ledger/describe.go index 7a60bc61..122f2246 100644 --- a/components/mdz/pkg/cmd/ledger/describe.go +++ b/components/mdz/pkg/cmd/ledger/describe.go @@ -84,10 +84,12 @@ func (f *factoryLedgerDescribe) runE(cmd *cobra.Command, _ []string) error { func (f *factoryLedgerDescribe) describePrint(led *mmodel.Ledger) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) tbl.AddRow("ID:", led.ID) diff --git a/components/mdz/pkg/cmd/ledger/list.go b/components/mdz/pkg/cmd/ledger/list.go index 530bb78b..bfab4e30 100644 --- a/components/mdz/pkg/cmd/ledger/list.go +++ b/components/mdz/pkg/cmd/ledger/list.go @@ -50,9 +50,6 @@ func (f *factoryLedgerList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "NAME", @@ -61,7 +58,12 @@ func (f *factoryLedgerList) runE(cmd *cobra.Command, _ []string) error { "CREATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range leds.Items { diff --git a/components/mdz/pkg/cmd/ledger/update.go b/components/mdz/pkg/cmd/ledger/update.go index e65558d3..f0fa075a 100644 --- a/components/mdz/pkg/cmd/ledger/update.go +++ b/components/mdz/pkg/cmd/ledger/update.go @@ -3,7 +3,6 @@ package ledger import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -73,8 +72,7 @@ func (f *factoryLedgerUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Ledger %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Ledger", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/organization/create.go b/components/mdz/pkg/cmd/organization/create.go index 563f4e4f..3ec83abd 100644 --- a/components/mdz/pkg/cmd/organization/create.go +++ b/components/mdz/pkg/cmd/organization/create.go @@ -3,7 +3,6 @@ package organization import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -62,8 +61,7 @@ func (f *factoryOrganizationCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The organization_id %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Organization", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/organization/create_test.go b/components/mdz/pkg/cmd/organization/create_test.go index 068e8a15..621a5962 100644 --- a/components/mdz/pkg/cmd/organization/create_test.go +++ b/components/mdz/pkg/cmd/organization/create_test.go @@ -2,9 +2,10 @@ package organization import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -79,5 +80,5 @@ func TestRunE(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The organization_id 123 has been successfully created") + assert.Contains(t, output, "The Organization 123 has been successfully created.") } diff --git a/components/mdz/pkg/cmd/organization/delete.go b/components/mdz/pkg/cmd/organization/delete.go index 7edd972c..d87546d1 100644 --- a/components/mdz/pkg/cmd/organization/delete.go +++ b/components/mdz/pkg/cmd/organization/delete.go @@ -1,8 +1,6 @@ package organization import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -35,8 +33,7 @@ func (f *factoryOrganizationDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Organization %s has been successfully deleted.", f.organizationID)) + output.FormatAndPrint(f.factory, f.organizationID, "Organization", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/organization/delete_test.go b/components/mdz/pkg/cmd/organization/delete_test.go index 85b27d6c..be81738a 100644 --- a/components/mdz/pkg/cmd/organization/delete_test.go +++ b/components/mdz/pkg/cmd/organization/delete_test.go @@ -2,9 +2,10 @@ package organization import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" diff --git a/components/mdz/pkg/cmd/organization/describe.go b/components/mdz/pkg/cmd/organization/describe.go index 0f9b0178..8e64196c 100644 --- a/components/mdz/pkg/cmd/organization/describe.go +++ b/components/mdz/pkg/cmd/organization/describe.go @@ -64,10 +64,12 @@ func (f *factoryOrganizationDescribe) runE(cmd *cobra.Command, _ []string) error func (f *factoryOrganizationDescribe) describePrint(org *mmodel.Organization) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) f.addBasicFields(tbl, org) diff --git a/components/mdz/pkg/cmd/organization/list.go b/components/mdz/pkg/cmd/organization/list.go index 0fe5e5e8..7bf92724 100644 --- a/components/mdz/pkg/cmd/organization/list.go +++ b/components/mdz/pkg/cmd/organization/list.go @@ -39,9 +39,6 @@ func (f *factoryOrganizationList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "PARENT_ORGANIZATION_ID", @@ -54,7 +51,12 @@ func (f *factoryOrganizationList) runE(cmd *cobra.Command, _ []string) error { "UPDATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + columnFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range orgs.Items { diff --git a/components/mdz/pkg/cmd/organization/list_test.go b/components/mdz/pkg/cmd/organization/list_test.go index dad9b796..0b97cba2 100644 --- a/components/mdz/pkg/cmd/organization/list_test.go +++ b/components/mdz/pkg/cmd/organization/list_test.go @@ -2,10 +2,11 @@ package organization import ( "bytes" - "go.uber.org/mock/gomock" "testing" "time" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" diff --git a/components/mdz/pkg/cmd/organization/update.go b/components/mdz/pkg/cmd/organization/update.go index f34a9bb1..a72a2db6 100644 --- a/components/mdz/pkg/cmd/organization/update.go +++ b/components/mdz/pkg/cmd/organization/update.go @@ -3,7 +3,6 @@ package organization import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -72,8 +71,7 @@ func (f *factoryOrganizationUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Organization %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Organization", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/organization/update_test.go b/components/mdz/pkg/cmd/organization/update_test.go index 52b310aa..c89b4ed7 100644 --- a/components/mdz/pkg/cmd/organization/update_test.go +++ b/components/mdz/pkg/cmd/organization/update_test.go @@ -2,9 +2,10 @@ package organization import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" diff --git a/components/mdz/pkg/cmd/portfolio/create.go b/components/mdz/pkg/cmd/portfolio/create.go index e08bb9fe..4e8049de 100644 --- a/components/mdz/pkg/cmd/portfolio/create.go +++ b/components/mdz/pkg/cmd/portfolio/create.go @@ -3,7 +3,6 @@ package portfolio import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -74,8 +73,7 @@ func (f *factoryPortfolioCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Portfolio ID %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Portfolio", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/portfolio/create_test.go b/components/mdz/pkg/cmd/portfolio/create_test.go index 1f40c775..e3cdb6d2 100644 --- a/components/mdz/pkg/cmd/portfolio/create_test.go +++ b/components/mdz/pkg/cmd/portfolio/create_test.go @@ -2,9 +2,10 @@ package portfolio import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -83,6 +84,6 @@ func Test_newCmdPortfolioCreate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Portfolio ID 01931c99-adef-7b98-ad68-72d7e263066a has been successfully created") + assert.Contains(t, output, "The Portfolio 01931c99-adef-7b98-ad68-72d7e263066a has been successfully created.") } diff --git a/components/mdz/pkg/cmd/portfolio/delete.go b/components/mdz/pkg/cmd/portfolio/delete.go index 63379257..1c42f3cf 100644 --- a/components/mdz/pkg/cmd/portfolio/delete.go +++ b/components/mdz/pkg/cmd/portfolio/delete.go @@ -1,8 +1,6 @@ package portfolio import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -63,8 +61,7 @@ func (f *factoryPortfolioDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Portfolio ID %s has been successfully deleted.", f.PortfolioID)) + output.FormatAndPrint(f.factory, f.PortfolioID, "Portfolio", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/portfolio/delete_test.go b/components/mdz/pkg/cmd/portfolio/delete_test.go index cef5de34..f81dd260 100644 --- a/components/mdz/pkg/cmd/portfolio/delete_test.go +++ b/components/mdz/pkg/cmd/portfolio/delete_test.go @@ -2,9 +2,10 @@ package portfolio import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -42,5 +43,5 @@ func Test_newCmdPortfolioDelete(t *testing.T) { assert.NoError(t, err) output := portfolioFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Portfolio ID 444 has been successfully deleted.") + assert.Contains(t, output, "The Portfolio 444 has been successfully deleted.") } diff --git a/components/mdz/pkg/cmd/portfolio/describe.go b/components/mdz/pkg/cmd/portfolio/describe.go index 19a580b0..57aafba0 100644 --- a/components/mdz/pkg/cmd/portfolio/describe.go +++ b/components/mdz/pkg/cmd/portfolio/describe.go @@ -106,10 +106,12 @@ func (f *factoryPortfolioDescribe) outputPortfolio(cmd *cobra.Command, asset *mm func (f *factoryPortfolioDescribe) describePrint(asset *mmodel.Portfolio) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) tbl.AddRow("ID:", asset.ID) diff --git a/components/mdz/pkg/cmd/portfolio/list.go b/components/mdz/pkg/cmd/portfolio/list.go index f24d4c15..ab447bd6 100644 --- a/components/mdz/pkg/cmd/portfolio/list.go +++ b/components/mdz/pkg/cmd/portfolio/list.go @@ -60,9 +60,6 @@ func (f *factoryPortfolioList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "NAME", @@ -72,7 +69,12 @@ func (f *factoryPortfolioList) runE(cmd *cobra.Command, _ []string) error { "CREATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range portfolios.Items { diff --git a/components/mdz/pkg/cmd/portfolio/update.go b/components/mdz/pkg/cmd/portfolio/update.go index e36d23eb..47d6a2b1 100644 --- a/components/mdz/pkg/cmd/portfolio/update.go +++ b/components/mdz/pkg/cmd/portfolio/update.go @@ -3,7 +3,6 @@ package portfolio import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -91,8 +90,7 @@ func (f *factoryPortfolioUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Portfolio ID %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Portfolio", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/portfolio/update_test.go b/components/mdz/pkg/cmd/portfolio/update_test.go index 00aa591b..32006c40 100644 --- a/components/mdz/pkg/cmd/portfolio/update_test.go +++ b/components/mdz/pkg/cmd/portfolio/update_test.go @@ -2,9 +2,10 @@ package portfolio import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -70,5 +71,5 @@ func Test_newCmdPortfolioUpdate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Portfolio ID 412 has been successfully updated.") + assert.Contains(t, output, "The Portfolio 412 has been successfully updated.") } diff --git a/components/mdz/pkg/cmd/product/create.go b/components/mdz/pkg/cmd/product/create.go index a5ec48d8..5a5b2c63 100644 --- a/components/mdz/pkg/cmd/product/create.go +++ b/components/mdz/pkg/cmd/product/create.go @@ -3,7 +3,6 @@ package product import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -73,8 +72,7 @@ func (f *factoryProductCreate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Product ID %s has been successfully created", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Product", output.Created) return nil } diff --git a/components/mdz/pkg/cmd/product/create_test.go b/components/mdz/pkg/cmd/product/create_test.go index 53f7a76f..5c9039bf 100644 --- a/components/mdz/pkg/cmd/product/create_test.go +++ b/components/mdz/pkg/cmd/product/create_test.go @@ -2,9 +2,10 @@ package product import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -80,6 +81,6 @@ func Test_newCmdProductCreate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Product ID 01931c99-adef-7b98-ad68-72d7e263066a has been successfully created") + assert.Contains(t, output, "The Product 01931c99-adef-7b98-ad68-72d7e263066a has been successfully created.") } diff --git a/components/mdz/pkg/cmd/product/delete.go b/components/mdz/pkg/cmd/product/delete.go index 555aac6f..850e61de 100644 --- a/components/mdz/pkg/cmd/product/delete.go +++ b/components/mdz/pkg/cmd/product/delete.go @@ -1,8 +1,6 @@ package product import ( - "fmt" - "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" "github.com/LerianStudio/midaz/components/mdz/pkg/cmd/utils" @@ -63,8 +61,7 @@ func (f *factoryProductDelete) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Product ID %s has been successfully deleted.", f.ProductID)) + output.FormatAndPrint(f.factory, f.ProductID, "Product", output.Deleted) return nil } diff --git a/components/mdz/pkg/cmd/product/delete_test.go b/components/mdz/pkg/cmd/product/delete_test.go index 8b96b923..1a62c727 100644 --- a/components/mdz/pkg/cmd/product/delete_test.go +++ b/components/mdz/pkg/cmd/product/delete_test.go @@ -2,9 +2,10 @@ package product import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -42,5 +43,5 @@ func Test_newCmdProductDelete(t *testing.T) { assert.NoError(t, err) output := factory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Product ID 444 has been successfully deleted.") + assert.Contains(t, output, "The Product 444 has been successfully deleted.") } diff --git a/components/mdz/pkg/cmd/product/describe.go b/components/mdz/pkg/cmd/product/describe.go index 834bb910..a4796539 100644 --- a/components/mdz/pkg/cmd/product/describe.go +++ b/components/mdz/pkg/cmd/product/describe.go @@ -106,10 +106,12 @@ func (f *factoryProductDescribe) outputProduct(cmd *cobra.Command, asset *mmodel func (f *factoryProductDescribe) describePrint(asset *mmodel.Product) { tbl := table.New("FIELDS", "VALUES") - headerFmt := color.New(color.FgYellow).SprintfFunc() - fieldFmt := color.New(color.FgYellow).SprintfFunc() + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) tbl.WithWriter(f.factory.IOStreams.Out) tbl.AddRow("ID:", asset.ID) diff --git a/components/mdz/pkg/cmd/product/list.go b/components/mdz/pkg/cmd/product/list.go index d0b66475..f5ad1502 100644 --- a/components/mdz/pkg/cmd/product/list.go +++ b/components/mdz/pkg/cmd/product/list.go @@ -60,9 +60,6 @@ func (f *factoryProductList) runE(cmd *cobra.Command, _ []string) error { return nil } - headerFmt := color.New(color.FgYellow).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - tbl := table.New( "ID", "NAME", @@ -71,7 +68,12 @@ func (f *factoryProductList) runE(cmd *cobra.Command, _ []string) error { "CREATED_AT", ) - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) + if !f.factory.NoColor { + headerFmt := color.New(color.FgYellow).SprintfFunc() + fieldFmt := color.New(color.FgYellow).SprintfFunc() + tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(fieldFmt) + } + tbl.WithWriter(f.factory.IOStreams.Out) for _, i := range portfolios.Items { diff --git a/components/mdz/pkg/cmd/product/update.go b/components/mdz/pkg/cmd/product/update.go index af45891d..3244ef9f 100644 --- a/components/mdz/pkg/cmd/product/update.go +++ b/components/mdz/pkg/cmd/product/update.go @@ -3,7 +3,6 @@ package product import ( "encoding/json" "errors" - "fmt" "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/internal/rest" @@ -91,8 +90,7 @@ func (f *factoryProductUpdate) runE(cmd *cobra.Command, _ []string) error { return err } - output.Printf(f.factory.IOStreams.Out, - fmt.Sprintf("The Product ID %s has been successfully updated.", resp.ID)) + output.FormatAndPrint(f.factory, resp.ID, "Product", output.Updated) return nil } diff --git a/components/mdz/pkg/cmd/product/update_test.go b/components/mdz/pkg/cmd/product/update_test.go index e210583c..1a91751e 100644 --- a/components/mdz/pkg/cmd/product/update_test.go +++ b/components/mdz/pkg/cmd/product/update_test.go @@ -2,9 +2,10 @@ package product import ( "bytes" - "go.uber.org/mock/gomock" "testing" + "go.uber.org/mock/gomock" + "github.com/LerianStudio/midaz/components/mdz/internal/domain/repository" "github.com/LerianStudio/midaz/components/mdz/pkg/factory" "github.com/LerianStudio/midaz/components/mdz/pkg/iostreams" @@ -70,5 +71,5 @@ func Test_newCmdProductUpdate(t *testing.T) { assert.NoError(t, err) output := orgFactory.factory.IOStreams.Out.(*bytes.Buffer).String() - assert.Contains(t, output, "The Product ID 412 has been successfully updated.") + assert.Contains(t, output, "The Product 412 has been successfully updated.") } diff --git a/components/mdz/pkg/cmd/root/root.go b/components/mdz/pkg/cmd/root/root.go index 716886bb..3c722b9a 100644 --- a/components/mdz/pkg/cmd/root/root.go +++ b/components/mdz/pkg/cmd/root/root.go @@ -35,6 +35,7 @@ func (f *factoryRoot) setCmds(cmd *cobra.Command) { } func (f *factoryRoot) setFlags(cmd *cobra.Command) { + cmd.PersistentFlags().BoolVar(&f.factory.NoColor, "no-color", false, "Changes the output format passing the json value to the flag") cmd.Flags().BoolP("help", "h", false, "Displays more information about the Mdz CLI") } diff --git a/components/mdz/pkg/factory/factory.go b/components/mdz/pkg/factory/factory.go index 9201af95..3a7e686f 100644 --- a/components/mdz/pkg/factory/factory.go +++ b/components/mdz/pkg/factory/factory.go @@ -15,6 +15,11 @@ type Factory struct { HTTPClient *http.Client IOStreams *iostreams.IOStreams Env *environment.Env + Flags +} + +type Flags struct { + NoColor bool } func NewFactory(env *environment.Env) *Factory { diff --git a/components/mdz/pkg/output/output.go b/components/mdz/pkg/output/output.go index 39f4ef1b..256b6166 100644 --- a/components/mdz/pkg/output/output.go +++ b/components/mdz/pkg/output/output.go @@ -4,12 +4,74 @@ import ( "fmt" "io" "log" + + "github.com/LerianStudio/midaz/components/mdz/pkg/factory" + "github.com/fatih/color" +) + +const ( + Created = "created" + Deleted = "deleted" + Updated = "updated" +) + +var ( + // IDs in pink and bold + idStyle = color.New(color.FgHiMagenta, color.Bold).SprintFunc() + + // Confirmations: "Y" in green and "N" in red + // yesStyle = color.New(color.FgGreen).SprintFunc() + // noStyle = color.New(color.FgRed).SprintFunc() + + // entitys in blue and bold + entityStyle = color.New(color.FgBlue, color.Bold).SprintFunc() + + // HTTP methods in specific colors + postStyle = color.New(color.FgYellow, color.Bold).SprintFunc() + deleteStyle = color.New(color.FgRed, color.Bold).SprintFunc() + // putStyle = color.New(color.FgBlue, color.Bold).SprintFunc() + patchStyle = color.New(color.FgBlue, color.Bold).SprintFunc() + // getStyle = color.New(color.FgGreen, color.Bold).SprintFunc() ) type Output interface { Output() error } +// FormatAndPrint formats and prints a message indicating the success of an operation, +// with or without style, depending on the color configuration. +func FormatAndPrint(f *factory.Factory, id, entity, method string) { + var msg, methodStyle string + + if f.NoColor { + msg = fmt.Sprintf("The %s %s has been successfully %s.", + entity, + id, + method, + ) + } else { + switch method { + case Created: + methodStyle = postStyle(method) + case Deleted: + methodStyle = deleteStyle(method) + case Updated: + methodStyle = patchStyle(method) + default: + methodStyle = method + } + + msg = fmt.Sprintf("✔︎ The %s %s has been successfully %s.", + entityStyle(entity), + idStyle(id), + methodStyle, + ) + } + + g := GeneralOutput{Msg: msg, Out: f.IOStreams.Out} + g.Output() +} + func Printf(w io.Writer, msg string) { g := GeneralOutput{Msg: msg, Out: w} g.Output()