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=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:
go clean && \
rm -rf bin/mac

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

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

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

@ -9,11 +9,24 @@ import (
// RootCmd ...
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 config, cmcAPIKey, apiChoice, colorscheme string
perPage := cointop.DefaultPerPage
cacheDir := cointop.DefaultCacheDir
var config string
var cmcAPIKey string
var apiChoice string
var colorscheme string
var perPage = cointop.DefaultPerPage
var cacheDir = cointop.DefaultCacheDir
var colorsDir string
rootCmd := &cobra.Command{
Use: "cointop",
@ -66,6 +79,7 @@ See git.io/cointop for more info.`,
ct, err := cointop.NewCointop(&cointop.Config{
CacheDir: cacheDir,
ColorsDir: colorsDir,
NoCache: noCache,
ConfigFilepath: config,
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(&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(&colorsDir, "colors-dir", "", colorsDir, "Colorschemes directory")
return rootCmd
}

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

@ -46,5 +46,5 @@ func NormalizePath(path string) string {
path = strings.Replace(path, ":PREFERRED_CONFIG_HOME:", userConfigHome, -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
}
} 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) {
// NOTE: case for when cointop is set as the theme but the colorscheme file doesn't exist
if ct.colorschemeName == "cointop" {

@ -66,6 +66,7 @@ func (s *Server) ListenAndServe() error {
Addr: fmt.Sprintf("%s:%v", s.address, s.port),
IdleTimeout: s.idleTimeout,
Handler: func(sshSession ssh.Session) {
cmdUserArgs := sshSession.Command()
ptyReq, winCh, isPty := sshSession.Pty()
if !isPty {
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)
colorsDir := pathutil.NormalizePath("~/.config/cointop/colors")
cmdCtx, cancelCmd := context.WithCancel(sshSession.Context())
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))
f, err := pty.Start(cmd)

Loading…
Cancel
Save