Skip to content

Commit

Permalink
Price command flag alias
Browse files Browse the repository at this point in the history
Remove top empty line
  • Loading branch information
miguelmota committed Feb 16, 2021
1 parent 99bbead commit 0576b04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion cmd/commands/price.go
@@ -1,21 +1,30 @@
package cmd

import (
"errors"

"github.com/miguelmota/cointop/cointop"
"github.com/spf13/cobra"
)

// PriceCmd ...
func PriceCmd() *cobra.Command {
var apiChoice string
var coin string
var coins []string
var currency string

priceCmd := &cobra.Command{
Use: "price",
Short: "Displays the current price of a coin",
Short: "Displays the current price of coin(s)",
Long: `The price command display the current price of a coin`,
RunE: func(cmd *cobra.Command, args []string) error {
if coin != "" {
if len(coins) > 0 {
return errors.New("flags --coin and --coins cannot be used at the same time")
}
coins = append(coins, coin)
}
return cointop.PrintPrices(&cointop.PricesConfig{
Coins: coins,
Currency: currency,
Expand All @@ -25,6 +34,7 @@ func PriceCmd() *cobra.Command {
}

priceCmd.Flags().StringSliceVarP(&coins, "coins", "c", nil, "Name or symbol of coin(s), comma separated. E.g. \"Bitcoin\" Eg. \"btc,eth,doge\"")
priceCmd.Flags().StringVarP(&coin, "coin", "", "", "Name or symbol of coin. Alias for --coins")
priceCmd.Flags().StringVarP(&currency, "currency", "f", "USD", "The currency to convert to")
priceCmd.Flags().StringVarP(&apiChoice, "api", "a", cointop.CoinGecko, "API choice. Available choices are \"coinmarketcap\" and \"coingecko\"")

Expand Down
8 changes: 4 additions & 4 deletions cointop/layout.go
Expand Up @@ -48,7 +48,7 @@ func (ct *Cointop) layout() error {
ct.Views.Marketbar.SetBacking(nil)
}
} else {
if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset, maxX, marketbarHeight+1); err != nil {
if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset-1, maxX, marketbarHeight+1); err != nil {
ct.Views.Marketbar.SetFrame(false)
ct.Views.Marketbar.SetFgColor(ct.colorscheme.gocuiFgColor(ct.Views.Marketbar.Name()))
ct.Views.Marketbar.SetBgColor(ct.colorscheme.gocuiBgColor(ct.Views.Marketbar.Name()))
Expand All @@ -73,7 +73,7 @@ func (ct *Cointop) layout() error {
ct.Views.Chart.SetBacking(nil)
}
} else {
if err := ct.ui.SetView(ct.Views.Chart, 0, topOffset, maxX, topOffset+chartHeight); err != nil {
if err := ct.ui.SetView(ct.Views.Chart, 0, topOffset-1, maxX, topOffset+chartHeight); err != nil {
ct.Views.Chart.Clear()
ct.Views.Chart.SetFrame(false)
ct.Views.Chart.SetFgColor(ct.colorscheme.gocuiFgColor(ct.Views.Chart.Name()))
Expand All @@ -92,15 +92,15 @@ func (ct *Cointop) layout() error {

tableOffsetX := ct.State.tableOffsetX
topOffset = topOffset + chartHeight
if err := ct.ui.SetView(ct.Views.TableHeader, tableOffsetX, topOffset, maxX, topOffset+2); err != nil {
if err := ct.ui.SetView(ct.Views.TableHeader, tableOffsetX, topOffset-1, maxX, topOffset+1); err != nil {
ct.Views.TableHeader.SetFrame(false)
ct.Views.TableHeader.SetFgColor(ct.colorscheme.gocuiFgColor(ct.Views.TableHeader.Name()))
ct.Views.TableHeader.SetBgColor(ct.colorscheme.gocuiBgColor(ct.Views.TableHeader.Name()))
go ct.UpdateTableHeader()
}

topOffset = topOffset + headerHeight
if err := ct.ui.SetView(ct.Views.Table, tableOffsetX, topOffset, maxX, maxY-statusbarHeight); err != nil {
if err := ct.ui.SetView(ct.Views.Table, tableOffsetX, topOffset-1, maxX, maxY-statusbarHeight); err != nil {
ct.Views.Table.SetFrame(false)
ct.Views.Table.SetHighlight(true)
ct.Views.Table.SetSelFgColor(ct.colorscheme.gocuiFgColor("table_row_active"))
Expand Down

0 comments on commit 0576b04

Please sign in to comment.