Ejemplo n.º 1
0
func PrintTableReport(typ string, running bool) error {
	logger.Debugf("PrintTableReport Initialized =>\t%s:%v\n", typ, running)
	conts := util.ErisContainersByType(typ, running)
	if len(conts) == 0 {
		return nil
	}

	var head string
	if typ == "chain" {
		head, _ = util.GetHead()
	}

	table := tablewriter.NewWriter(config.GlobalConfig.Writer)
	table.SetHeader([]string{"SERVICE NAME", "CONTAINER NAME", "TYPE", "CONTAINER #", "PORTS"})
	for _, c := range conts {
		n, _ := PrintLineByContainerName(c.FullName)
		if typ == "chain" {
			if n[0] == head {
				n[0] = fmt.Sprintf("**  %s", n[0]) // TODO: colorize this when we settle on a lib
			}
		}
		table.Append(n)
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()
	return nil
}
Ejemplo n.º 2
0
func CurrentChain(do *definitions.Do) error {
	head, _ := util.GetHead()

	if head == "" {
		head = "There is no chain checked out."
	}

	log.Warn(head)
	do.Result = head

	return nil
}
Ejemplo n.º 3
0
func CheckoutChain(do *definitions.Do) error {
	if do.Name == "" {
		do.Result = "nil"
		return util.NullHead()
	}

	curHead, _ := util.GetHead()
	if do.Name == curHead {
		do.Result = "no change"
		return nil
	}

	return util.ChangeHead(do.Name)
}
Ejemplo n.º 4
0
func PrintTableReport(typ string, existing, all bool) (string, error) {
	log.WithField("type", typ).Debug("Table report initialized")

	var conts []*util.ContainerName
	if !all {
		conts = util.ErisContainersByType(typ, existing)
	}
	// "MACHINE" is placeholder
	header := []string{"NAME", "MACHINE", "RUNNING", "CONTAINER NAME", "PORTS"}
	if err := util.CheckParts(header); err != nil {
		log.Error(err) // err is silenced by some funcs
		return "", err
	}

	buf := new(bytes.Buffer)
	table := tablewriter.NewWriter(buf)
	//name set by logger instead
	table.SetHeader(header)

	if all { //get all the things
		parts, _ := AssembleTable(typ)
		for _, p := range parts {
			table.Append(formatLine(p))
		}
	} else {
		for _, c := range conts {
			n, _ := PrintLineByContainerName(c.FullName, existing)
			if typ == "chain" {
				head, _ := util.GetHead()
				if n[0] == head {
					n[0] = fmt.Sprintf("**  %s", n[0])
				}
			}
			table.Append(n)
		}
	}

	// Styling
	table.SetBorder(false)
	table.SetCenterSeparator(" ")
	table.SetColumnSeparator(" ")
	table.SetRowSeparator("-")
	table.SetAlignment(tablewriter.ALIGN_LEFT)
	table.Render()

	return buf.String(), nil
}
Ejemplo n.º 5
0
func ListKnown(do *definitions.Do) error {
	head, _ := util.GetHead()
	chns := util.GetGlobalLevelConfigFilesByType("chains", false)
	var chainsNew []string
	for _, c := range chns {
		switch c {
		case "default":
			continue
		case head:
			chainsNew = append(chainsNew, fmt.Sprintf("*\t%s", c))
		default:
			chainsNew = append(chainsNew, fmt.Sprintf("\t%s", c))
		}
		// if c == head {
		// } else {
		// }
	}
	do.Result = strings.Join(chainsNew, "\n")
	return nil
}
Ejemplo n.º 6
0
//looks for definition files in ~/.eris/typ
func ListKnown(typ string) (result string, err error) {

	result = strings.Join(util.GetGlobalLevelConfigFilesByType(typ, false), "\n")

	if typ == "chains" {
		var chainsNew []string
		head, _ := util.GetHead()
		chns := util.GetGlobalLevelConfigFilesByType(typ, false)

		for _, c := range chns {
			switch c {
			case "default":
				continue
			case head:
				chainsNew = append(chainsNew, fmt.Sprintf("*%s", c))
			default:
				chainsNew = append(chainsNew, fmt.Sprintf("%s", c))
			}
		}
		result = strings.Join(chainsNew, "\n")
	}
	return result, nil
}
Ejemplo n.º 7
0
func ConnectChainToService(chainFlag, chainNameAndOpts string, srv *definitions.ServiceDefinition) (*definitions.ServiceDefinition, error) {
	chainName, internalName, link, mount := util.ParseDependency(chainNameAndOpts)
	if chainFlag != "" {
		// flag overwrites whatever is in the service definition
		chainName = chainFlag
	} else if strings.HasPrefix(srv.Chain, "$chain") {
		// if there's a $chain and no flag or checked out chain, we err
		var err error
		chainName, err = util.GetHead()
		if chainName == "" || err != nil {
			return nil, fmt.Errorf("Marmot disapproval face.\nYou tried to start a service which has a `$chain` variable but didn't give us a chain.\nPlease rerun the command either after [eris chains checkout CHAINNAME] *or* with a --chain flag.\n")
		}
	}
	s, err := loaders.ChainsAsAService(chainName, false, srv.Operations.ContainerNumber)
	if err != nil {
		return nil, err
	}
	// link the service container linked to the chain
	// XXX: we may have name collision here if we're not careful.
	loaders.ConnectToAChain(srv.Service, srv.Operations, chainName, internalName, link, mount)

	return s, nil
}
Ejemplo n.º 8
0
Made with <3 by Eris Industries.

Complete documentation is available at https://docs.erisindustries.com
` + "\nVersion:\n  " + VERSION,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		var logLevel log.LogLevel
		if do.Verbose {
			logLevel = 2
		} else if do.Debug {
			logLevel = 3
		}
		log.SetLoggers(logLevel, config.GlobalConfig.Writer, config.GlobalConfig.ErrorWriter)

		common.InitErisDir()
		util.DockerConnect(do.Verbose, do.MachineName)
		do.ChainName, _ = util.GetHead()
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		err := config.SaveGlobalConfig(config.GlobalConfig.Config)
		if err != nil {
			logger.Errorln(err)
		}
		log.Flush()
	},
}

func Execute() {
	InitializeConfig()
	AddGlobalFlags()
	AddCommands()
	ErisCmd.Execute()