-
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
9 changed files
with
451 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,76 @@ | ||
/* | ||
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package currency | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/slntopp/nocloud-cli/pkg/tools" | ||
"github.com/slntopp/nocloud/pkg/billing/proto" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var CreateCmd = &cobra.Command{ | ||
Use: "create [flags]", | ||
Aliases: []string{"crt", "c"}, | ||
Short: "Create Exchange rate", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var ( | ||
from int | ||
to int | ||
rate float64 | ||
) | ||
from, err := cmd.Flags().GetInt("from") | ||
if err != nil || from == -1 { | ||
return errors.New("empty from") | ||
} | ||
to, err = cmd.Flags().GetInt("to") | ||
if err != nil || to == -1 { | ||
return errors.New("empty to") | ||
} | ||
rate, err = cmd.Flags().GetFloat64("rate") | ||
if err != nil { | ||
return errors.New("empty rate") | ||
} | ||
|
||
ctx, client := MakeCurrencyServiceClientOrFail() | ||
res, err := client.CreateExchangeRate(ctx, &proto.CreateExchangeRateRequest{ | ||
From: proto.Currency(from), | ||
To: proto.Currency(to), | ||
Rate: rate, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, res) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Println("Successfully created ", res) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
CreateCmd.Flags().Int("from", -1, "") | ||
CreateCmd.Flags().Int("to", -1, "") | ||
CreateCmd.Flags().Float64("rate", 1.0, "") | ||
} |
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 @@ | ||
/* | ||
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package currency | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/slntopp/nocloud-cli/pkg/tools" | ||
"github.com/slntopp/nocloud/pkg/billing/proto" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// DeleteCmd represents the delete command | ||
var DeleteCmd = &cobra.Command{ | ||
Use: "delete [flags]", | ||
Aliases: []string{"del", "rm", "r"}, | ||
Short: "Delete exchange rate", | ||
Args: cobra.MinimumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var ( | ||
from int | ||
to int | ||
) | ||
from, err := cmd.Flags().GetInt("from") | ||
if err != nil || from == -1 { | ||
return errors.New("empty from") | ||
} | ||
to, err = cmd.Flags().GetInt("to") | ||
if err != nil || to == -1 { | ||
return errors.New("empty to") | ||
} | ||
|
||
ctx, client := MakeCurrencyServiceClientOrFail() | ||
res, err := client.DeleteExchangeRate(ctx, &proto.DeleteExchangeRateRequest{ | ||
From: proto.Currency(from), | ||
To: proto.Currency(to), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, res) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Println("Success deleted ", res) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
DeleteCmd.Flags().Int("from", -1, "") | ||
DeleteCmd.Flags().Int("to", -1, "") | ||
} |
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 @@ | ||
/* | ||
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package currency | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/slntopp/nocloud-cli/pkg/tools" | ||
"github.com/slntopp/nocloud/pkg/billing/proto" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetCmd represents the get command | ||
var GetCmd = &cobra.Command{ | ||
Use: "get [flags]", | ||
Short: "Get exchange rate", | ||
Args: cobra.MinimumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var ( | ||
from int | ||
to int | ||
) | ||
from, err := cmd.Flags().GetInt("from") | ||
if err != nil || from == -1 { | ||
return errors.New("empty from") | ||
} | ||
to, err = cmd.Flags().GetInt("to") | ||
if err != nil || to == -1 { | ||
return errors.New("empty to") | ||
} | ||
|
||
ctx, client := MakeCurrencyServiceClientOrFail() | ||
res, err := client.GetExchangeRate(ctx, &proto.GetExchangeRateRequest{ | ||
From: proto.Currency(from), | ||
To: proto.Currency(to), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, res) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Println("Successfully fetched ", res) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
GetCmd.Flags().Int("from", -1, "") | ||
GetCmd.Flags().Int("to", -1, "") | ||
} |
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,72 @@ | ||
/* | ||
Copyright © 2021-2022 Nikita Ivanovski info@slnt-opp.xyz | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
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 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package currency | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/slntopp/nocloud-cli/pkg/tools" | ||
"github.com/slntopp/nocloud/pkg/billing/proto" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// ListCurrenciesCmd represents the list currencies command | ||
var ListCurrenciesCmd = &cobra.Command{ | ||
Use: "currencies", | ||
Aliases: []string{"curs"}, | ||
Short: "List currencies", | ||
Args: cobra.MinimumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, client := MakeCurrencyServiceClientOrFail() | ||
curs, err := client.GetCurrencies(ctx, &proto.GetCurrenciesRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, curs) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Println("Successfully fetched ", curs) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
// ListRatesCmd represents the list rates command | ||
var ListRatesCmd = &cobra.Command{ | ||
Use: "rates", | ||
Aliases: []string{"exchangerates"}, | ||
Short: "List exchange rates", | ||
Args: cobra.MinimumNArgs(0), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, client := MakeCurrencyServiceClientOrFail() | ||
rates, err := client.GetExchangeRates(ctx, &proto.GetExchangeRatesRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ok, err := tools.PrintJsonDataQ(cmd, rates) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
fmt.Println("Successfully fetched ", rates) | ||
} | ||
return nil | ||
}, | ||
} |
Oops, something went wrong.