2020-08-10 01:42:04 +00:00
package cmd
import (
"fmt"
"github.com/miguelmota/cointop/cointop"
"github.com/spf13/cobra"
)
// HoldingsCmd ...
func HoldingsCmd ( ) * cobra . Command {
2020-08-11 03:34:15 +00:00
var help bool
var total bool
var noCache bool
2020-08-10 01:42:04 +00:00
var config string
2020-08-11 03:34:15 +00:00
var sortBy string
var sortDesc bool
2020-08-11 05:23:46 +00:00
var format string = "table"
2020-08-11 03:34:15 +00:00
var humanReadable bool
2020-08-11 05:39:14 +00:00
var filter [ ] string
2020-09-06 02:17:49 +00:00
var convert string
2020-08-10 01:42:04 +00:00
holdingsCmd := & cobra . Command {
Use : "holdings" ,
Short : "Displays current holdings" ,
Long : ` The holdings command shows your current holdings ` ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2020-08-11 03:34:15 +00:00
if help {
return cmd . Help ( )
}
2020-08-10 01:42:04 +00:00
ct , err := cointop . NewCointop ( & cointop . Config {
ConfigFilepath : config ,
CacheDir : cointop . DefaultCacheDir ,
} )
if err != nil {
return err
}
if total {
2020-08-11 03:34:15 +00:00
return ct . PrintTotalHoldings ( & cointop . TablePrintOptions {
HumanReadable : humanReadable ,
2020-08-11 05:23:46 +00:00
Format : format ,
2020-08-11 05:39:14 +00:00
Filter : filter ,
2020-09-06 02:17:49 +00:00
Convert : convert ,
2020-08-11 03:34:15 +00:00
} )
2020-08-10 01:42:04 +00:00
}
2020-08-11 03:34:15 +00:00
return ct . PrintHoldingsTable ( & cointop . TablePrintOptions {
SortBy : sortBy ,
SortDesc : sortDesc ,
HumanReadable : humanReadable ,
2020-08-11 05:23:46 +00:00
Format : format ,
2020-08-11 05:39:14 +00:00
Filter : filter ,
2020-09-06 02:17:49 +00:00
Convert : convert ,
2020-08-11 03:34:15 +00:00
} )
2020-08-10 01:42:04 +00:00
} ,
}
2020-08-11 03:34:15 +00:00
holdingsCmd . Flags ( ) . BoolVarP ( & help , "help" , "" , help , "Help for holdings" )
holdingsCmd . Flags ( ) . BoolVarP ( & total , "total" , "t" , total , "Show total only" )
holdingsCmd . Flags ( ) . BoolVarP ( & noCache , "no-cache" , "" , noCache , "No cache" )
holdingsCmd . Flags ( ) . BoolVarP ( & humanReadable , "human" , "h" , humanReadable , "Human readable output" )
2020-08-10 01:42:04 +00:00
holdingsCmd . Flags ( ) . StringVarP ( & config , "config" , "c" , "" , fmt . Sprintf ( "Config filepath. (default %s)" , cointop . DefaultConfigFilepath ) )
2020-08-11 03:34:15 +00:00
holdingsCmd . Flags ( ) . StringVarP ( & sortBy , "sort-by" , "s" , sortBy , ` Sort by column. Options are "name", "symbol", "price", "holdings", "balance", "24h" ` )
holdingsCmd . Flags ( ) . BoolVarP ( & sortDesc , "sort-desc" , "d" , sortDesc , "Sort in descending order" )
2020-08-11 05:39:14 +00:00
holdingsCmd . Flags ( ) . StringVarP ( & format , "format" , "" , format , ` Ouput format. Options are "table", "csv", "json" ` )
2020-09-06 02:17:49 +00:00
holdingsCmd . Flags ( ) . StringSliceVarP ( & filter , "filter" , "" , filter , ` Filter portfolio entries by coin name or symbol, comma separated. Example: "btc,eth,doge" ` )
holdingsCmd . Flags ( ) . StringVarP ( & convert , "convert" , "f" , convert , "The currency to convert to" )
2020-08-10 01:42:04 +00:00
return holdingsCmd
}