Merge branch 'feature/ssh-flags' into master

pull/71/head
Miguel Mota 4 years ago
commit ac84b770b3

@ -41,6 +41,9 @@ build-multiple: clean
env GOARCH=amd64 go build -ldflags "-s -w -X github.com/miguelmota/cointop/cointop.version=$(VERSION)" -o bin/cointop64 && upx bin/cointop64 && \ env GOARCH=amd64 go build -ldflags "-s -w -X github.com/miguelmota/cointop/cointop.version=$(VERSION)" -o bin/cointop64 && upx bin/cointop64 && \
env GOARCH=386 go build -ldflags "-s -w -X github.com/miguelmota/cointop/cointop.version=$(VERSION)" -o bin/cointop32 && upx bin/cointop32 env GOARCH=386 go build -ldflags "-s -w -X github.com/miguelmota/cointop/cointop.version=$(VERSION)" -o bin/cointop32 && upx bin/cointop32
install: build
sudo mv bin/cointop /usr/local/bin
clean-mac: clean-mac:
go clean && \ go clean && \
rm -rf bin/mac rm -rf bin/mac

@ -615,6 +615,12 @@ SSH demo:
ssh cointop.sh ssh cointop.sh
``` ```
Passing arguments to SSH server:
```bash
ssh cointop.sh -t cointop --colorscheme synthwave
```
Using docker to run SSH server: Using docker to run SSH server:
```bash ```bash

@ -7,7 +7,8 @@ import (
// DominanceCmd ... // DominanceCmd ...
func DominanceCmd() *cobra.Command { func DominanceCmd() *cobra.Command {
var apiChoice, currency string var apiChoice string
var currency string
dominanceCmd := &cobra.Command{ dominanceCmd := &cobra.Command{
Use: "dominance", Use: "dominance",

@ -7,7 +7,9 @@ import (
// PriceCmd ... // PriceCmd ...
func PriceCmd() *cobra.Command { func PriceCmd() *cobra.Command {
var apiChoice, coin, currency string var apiChoice string
var coin string
var currency string
priceCmd := &cobra.Command{ priceCmd := &cobra.Command{
Use: "price", Use: "price",

@ -9,11 +9,24 @@ import (
// RootCmd ... // RootCmd ...
func RootCmd() *cobra.Command { func RootCmd() *cobra.Command {
var version, test, clean, reset, hideMarketbar, hideChart, hideStatusbar, onlyTable, silent, noCache bool var version bool
var test bool
var clean bool
var reset bool
var hideMarketbar bool
var hideChart bool
var hideStatusbar bool
var onlyTable bool
var silent bool
var noCache bool
var refreshRate uint var refreshRate uint
var config, cmcAPIKey, apiChoice, colorscheme string var config string
perPage := cointop.DefaultPerPage var cmcAPIKey string
cacheDir := cointop.DefaultCacheDir var apiChoice string
var colorscheme string
var perPage = cointop.DefaultPerPage
var cacheDir = cointop.DefaultCacheDir
var colorsDir string
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "cointop", Use: "cointop",
@ -66,6 +79,7 @@ See git.io/cointop for more info.`,
ct, err := cointop.NewCointop(&cointop.Config{ ct, err := cointop.NewCointop(&cointop.Config{
CacheDir: cacheDir, CacheDir: cacheDir,
ColorsDir: colorsDir,
NoCache: noCache, NoCache: noCache,
ConfigFilepath: config, ConfigFilepath: config,
CoinMarketCapAPIKey: cmcAPIKey, CoinMarketCapAPIKey: cmcAPIKey,
@ -103,6 +117,7 @@ See git.io/cointop for more info.`,
rootCmd.Flags().StringVarP(&apiChoice, "api", "", "", "API choice. Available choices are \"coinmarketcap\" and \"coingecko\"") rootCmd.Flags().StringVarP(&apiChoice, "api", "", "", "API choice. Available choices are \"coinmarketcap\" and \"coingecko\"")
rootCmd.Flags().StringVarP(&colorscheme, "colorscheme", "", "", fmt.Sprintf("Colorscheme to use (default \"cointop\").\n%s", cointop.ColorschemeHelpString())) rootCmd.Flags().StringVarP(&colorscheme, "colorscheme", "", "", fmt.Sprintf("Colorscheme to use (default \"cointop\").\n%s", cointop.ColorschemeHelpString()))
rootCmd.Flags().StringVarP(&cacheDir, "cache-dir", "", cacheDir, "Cache directory") rootCmd.Flags().StringVarP(&cacheDir, "cache-dir", "", cacheDir, "Cache directory")
rootCmd.Flags().StringVarP(&colorsDir, "colors-dir", "", colorsDir, "Colorschemes directory")
return rootCmd return rootCmd
} }

@ -81,6 +81,7 @@ type Cointop struct {
ActionsMap map[string]bool ActionsMap map[string]bool
apiKeys *APIKeys apiKeys *APIKeys
cache *cache.Cache cache *cache.Cache
colorsDir string
config config // toml config config config // toml config
configFilepath string configFilepath string
api api.Interface api api.Interface
@ -124,6 +125,7 @@ type Portfolio struct {
type Config struct { type Config struct {
APIChoice string APIChoice string
CacheDir string CacheDir string
ColorsDir string
Colorscheme string Colorscheme string
ConfigFilepath string ConfigFilepath string
CoinMarketCapAPIKey string CoinMarketCapAPIKey string
@ -154,6 +156,9 @@ var DefaultConfigFilepath = pathutil.NormalizePath(":PREFERRED_CONFIG_HOME:/coin
// DefaultCacheDir ... // DefaultCacheDir ...
var DefaultCacheDir = filecache.DefaultCacheDir var DefaultCacheDir = filecache.DefaultCacheDir
// DefaultColorsDir ...
var DefaultColorsDir = fmt.Sprintf("%s/colors", DefaultConfigFilepath)
// NewCointop initializes cointop // NewCointop initializes cointop
func NewCointop(config *Config) (*Cointop, error) { func NewCointop(config *Config) (*Cointop, error) {
var debug bool var debug bool
@ -189,6 +194,7 @@ func NewCointop(config *Config) (*Cointop, error) {
maxTableWidth: 175, maxTableWidth: 175,
ActionsMap: ActionsMap(), ActionsMap: ActionsMap(),
cache: cache.New(1*time.Minute, 2*time.Minute), cache: cache.New(1*time.Minute, 2*time.Minute),
colorsDir: config.ColorsDir,
configFilepath: configFilepath, configFilepath: configFilepath,
chartRanges: ChartRanges(), chartRanges: ChartRanges(),
debug: debug, debug: debug,

@ -46,5 +46,5 @@ func NormalizePath(path string) string {
path = strings.Replace(path, ":PREFERRED_CONFIG_HOME:", userConfigHome, -1) path = strings.Replace(path, ":PREFERRED_CONFIG_HOME:", userConfigHome, -1)
path = strings.Replace(path, "/", string(filepath.Separator), -1) path = strings.Replace(path, "/", string(filepath.Separator), -1)
return path return filepath.Clean(path)
} }

@ -335,7 +335,12 @@ func (ct *Cointop) getColorschemeColors() (map[string]interface{}, error) {
return nil, err return nil, err
} }
} else { } else {
path := fmt.Sprintf("%s/colors/%s.toml", ct.ConfigDirPath(), ct.colorschemeName) colorsDir := fmt.Sprintf("%s/colors", ct.ConfigDirPath())
if ct.colorsDir != "" {
colorsDir = pathutil.NormalizePath(ct.colorsDir)
}
path := fmt.Sprintf("%s/%s.toml", colorsDir, ct.colorschemeName)
if _, err := os.Stat(path); os.IsNotExist(err) { if _, err := os.Stat(path); os.IsNotExist(err) {
// NOTE: case for when cointop is set as the theme but the colorscheme file doesn't exist // NOTE: case for when cointop is set as the theme but the colorscheme file doesn't exist
if ct.colorschemeName == "cointop" { if ct.colorschemeName == "cointop" {

@ -66,6 +66,7 @@ func (s *Server) ListenAndServe() error {
Addr: fmt.Sprintf("%s:%v", s.address, s.port), Addr: fmt.Sprintf("%s:%v", s.address, s.port),
IdleTimeout: s.idleTimeout, IdleTimeout: s.idleTimeout,
Handler: func(sshSession ssh.Session) { Handler: func(sshSession ssh.Session) {
cmdUserArgs := sshSession.Command()
ptyReq, winCh, isPty := sshSession.Pty() ptyReq, winCh, isPty := sshSession.Pty()
if !isPty { if !isPty {
io.WriteString(sshSession, "Error: Non-interactive terminals are not supported") io.WriteString(sshSession, "Error: Non-interactive terminals are not supported")
@ -80,11 +81,31 @@ func (s *Server) ListenAndServe() error {
} }
configPath := fmt.Sprintf("%s/config", tempDir) configPath := fmt.Sprintf("%s/config", tempDir)
colorsDir := pathutil.NormalizePath("~/.config/cointop/colors")
cmdCtx, cancelCmd := context.WithCancel(sshSession.Context()) cmdCtx, cancelCmd := context.WithCancel(sshSession.Context())
defer cancelCmd() defer cancelCmd()
cmd := exec.CommandContext(cmdCtx, s.executableBinary, "--reset", "--silent", "--cache-dir", tempDir, "--config", configPath) flags := []string{
"--reset",
"--silent",
"--cache-dir",
tempDir,
"--config",
configPath,
"--colors-dir",
colorsDir,
}
for i, arg := range cmdUserArgs {
if i == 0 {
continue
}
flags = append(flags, arg)
}
cmd := exec.CommandContext(cmdCtx, s.executableBinary, flags...)
cmd.Env = append(sshSession.Environ(), fmt.Sprintf("TERM=%s", ptyReq.Term)) cmd.Env = append(sshSession.Environ(), fmt.Sprintf("TERM=%s", ptyReq.Term))
f, err := pty.Start(cmd) f, err := pty.Start(cmd)

Loading…
Cancel
Save