本文整理匯總了Golang中github.com/eris-ltd/eris-cli/util.GetFileByNameAndType函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetFileByNameAndType函數的具體用法?Golang GetFileByNameAndType怎麽用?Golang GetFileByNameAndType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetFileByNameAndType函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RmChain
func RmChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD); err != nil {
return err
}
} else {
logger.Infoln("That chain's container does not exist.")
}
if do.File {
oldFile := util.GetFileByNameAndType("chains", do.Name)
if err != nil {
return err
}
oldFile = path.Join(BlockchainsPath, oldFile) + ".toml"
logger.Printf("Removing file =>\t\t%s\n", oldFile)
if err := os.Remove(oldFile); err != nil {
return err
}
}
return nil
}
示例2: RmChain
func RmChain(do *definitions.Do) error {
chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsChainExisting(chain) {
if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil {
return err
}
} else {
log.Info("Chain container does not exist")
}
if do.File {
oldFile := util.GetFileByNameAndType("chains", do.Name)
if err != nil {
return err
}
log.WithField("file", oldFile).Warn("Removing file")
if err := os.Remove(oldFile); err != nil {
return err
}
}
return nil
}
示例3: RmService
func RmService(do *definitions.Do) error {
for _, servName := range do.Args {
service, err := loaders.LoadServiceDefinition(servName, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsServiceExisting(service.Service, service.Operations) {
err = perform.DockerRemove(service.Service, service.Operations, do.RmD)
if err != nil {
return err
}
}
if do.File {
oldFile := util.GetFileByNameAndType("services", servName)
if err != nil {
return err
}
oldFile = path.Join(ServicesPath, oldFile) + ".toml"
logger.Printf("Removing file =>\t\t%s\n", oldFile)
if err := os.Remove(oldFile); err != nil {
return err
}
}
}
do.Result = "success"
return nil
}
示例4: RenameAction
func RenameAction(do *definitions.Do) error {
if do.Name == do.NewName {
return fmt.Errorf("Cannot rename to same name")
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
do.NewName = strings.Replace(do.NewName, " ", "_", -1)
act, _, err := LoadActionDefinition(do.Name)
if err != nil {
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Debug("Failed renaming action")
return err
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
log.WithField("file", do.Name).Debug("Finding action definition file")
oldFile := util.GetFileByNameAndType("actions", do.Name)
if oldFile == "" {
return fmt.Errorf("Could not find that action definition file.")
}
log.WithField("file", oldFile).Debug("Found action definition file")
// if !strings.Contains(oldFile, ActionsPath) {
// oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
// }
var newFile string
newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)
if newNameBase == do.Name {
newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
} else {
newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
newFile = strings.Replace(newFile, " ", "_", -1)
}
if newFile == oldFile {
log.Info("Not renaming the same file")
return nil
}
act.Name = strings.Replace(newNameBase, "_", " ", -1)
log.WithFields(log.Fields{
"old": act.Name,
"new": newFile,
}).Debug("Writing new action definition file")
err = WriteActionDefinitionFile(act, newFile)
if err != nil {
return err
}
log.WithField("file", oldFile).Debug("Removing old file")
os.Remove(oldFile)
return nil
}
示例5: TestActionDefinitionFile
func TestActionDefinitionFile(name string) bool {
name = strings.Replace(name, " ", "_", -1)
if util.GetFileByNameAndType("actions", name) == "" {
return false
}
return true
}
示例6: RenameAction
func RenameAction(do *definitions.Do) error {
if do.Name == do.NewName {
return fmt.Errorf("Cannot rename to same name")
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
do.NewName = strings.Replace(do.NewName, " ", "_", -1)
act, _, err := LoadActionDefinition(do.Name)
if err != nil {
logger.Debugf("About to fail. Name:NewName =>\t%s:%s", do.Name, do.NewName)
return err
}
do.Name = strings.Replace(do.Name, " ", "_", -1)
logger.Debugf("About to find defFile =>\t%s\n", do.Name)
oldFile := util.GetFileByNameAndType("actions", do.Name)
if oldFile == "" {
return fmt.Errorf("Could not find that action definition file.")
}
logger.Debugf("Found defFile at =>\t\t%s\n", oldFile)
if !strings.Contains(oldFile, ActionsPath) {
oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
}
var newFile string
newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)
if newNameBase == do.Name {
newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
} else {
newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
newFile = strings.Replace(newFile, " ", "_", -1)
}
if newFile == oldFile {
logger.Infoln("Those are the same file. Not renaming")
return nil
}
act.Name = strings.Replace(newNameBase, "_", " ", -1)
logger.Debugf("About to write new def file =>\t%s:%s\n", act.Name, newFile)
err = WriteActionDefinitionFile(act, newFile)
if err != nil {
return err
}
logger.Debugf("Removing old file =>\t\t%s\n", oldFile)
os.Remove(oldFile)
return nil
}
示例7: RmAction
func RmAction(do *definitions.Do) error {
do.Name = strings.Join(do.Args, "_")
if do.File {
oldFile := util.GetFileByNameAndType("actions", do.Name)
if oldFile == "" {
return nil
}
if !strings.Contains(oldFile, ActionsPath) {
oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
}
logger.Debugf("Removing file =>\t\t%s\n", oldFile)
os.Remove(oldFile)
}
return nil
}
示例8: exportFile
func exportFile(chainName string) (string, error) {
fileName := util.GetFileByNameAndType("chains", chainName)
var hash string
var err error
if logger.Level > 0 {
hash, err = util.SendToIPFS(fileName, logger.Writer)
} else {
hash, err = util.SendToIPFS(fileName, bytes.NewBuffer([]byte{}))
}
if err != nil {
return "", err
}
return hash, nil
}
示例9: exportFile
func exportFile(chainName string) (string, error) {
fileName := util.GetFileByNameAndType("chains", chainName)
var hash string
var err error
if log.GetLevel() > 0 {
hash, err = ipfs.SendToIPFS(fileName, "", os.Stdout)
} else {
hash, err = ipfs.SendToIPFS(fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return "", err
}
return hash, nil
}
示例10: RmAction
func RmAction(do *definitions.Do) error {
do.Name = strings.Join(do.Operations.Args, "_")
if do.File {
oldFile := util.GetFileByNameAndType("actions", do.Name)
if oldFile == "" {
return nil
}
// if !strings.Contains(oldFile, ActionsPath) {
// oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
// }
log.WithField("file", oldFile).Debug("Removing file")
os.Remove(oldFile)
}
return nil
}
示例11: exportFile
func exportFile(actionName string) (string, error) {
var err error
fileName := util.GetFileByNameAndType("actions", actionName)
if fileName == "" {
return "", fmt.Errorf("no file to export")
}
var hash string
if logger.Level > 0 {
hash, err = ipfs.SendToIPFS(fileName, "", logger.Writer)
} else {
hash, err = ipfs.SendToIPFS(fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return "", err
}
return hash, nil
}
示例12: RenameChain
// XXX: What's going on here? => [csk]: magic
func RenameChain(do *definitions.Do) error {
if do.Name == do.NewName {
return fmt.Errorf("Cannot rename to same name")
}
newNameBase := strings.Replace(do.NewName, filepath.Ext(do.NewName), "", 1)
transformOnly := newNameBase == do.Name
if util.IsKnownChain(do.Name) {
log.WithFields(log.Fields{
"from": do.Name,
"to": do.NewName,
}).Info("Renaming chain")
log.WithField("=>", do.Name).Debug("Loading chain definition file")
chainDef, err := loaders.LoadChainDefinition(do.Name, false, 1) // TODO:CNUM
if err != nil {
return err
}
if !transformOnly {
log.Debug("Renaming chain container")
err = perform.DockerRename(chainDef.Operations, do.NewName)
if err != nil {
return err
}
}
oldFile := util.GetFileByNameAndType("chains", do.Name)
if err != nil {
return err
}
if filepath.Base(oldFile) == do.NewName {
log.Info("Those are the same file. Not renaming")
return nil
}
log.Debug("Renaming chain definition file")
var newFile string
if filepath.Ext(do.NewName) == "" {
newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
} else {
newFile = filepath.Join(ChainsPath, do.NewName)
}
chainDef.Name = newNameBase
// Generally we won't want to use Service.Name
// as it will be confused with the Name.
chainDef.Service.Name = ""
// Service.Image should be taken from the default.toml.
chainDef.Service.Image = ""
err = WriteChainDefinitionFile(chainDef, newFile)
if err != nil {
return err
}
if !transformOnly {
log.WithFields(log.Fields{
"from": fmt.Sprintf("%s:%d", do.Name, chainDef.Operations.ContainerNumber),
"to": fmt.Sprintf("%s:%d", do.NewName, chainDef.Operations.ContainerNumber),
}).Info("Renaming chain data container")
do.Operations.ContainerNumber = chainDef.Operations.ContainerNumber
err = data.RenameData(do)
if err != nil {
return err
}
}
os.Remove(oldFile)
} else {
return fmt.Errorf("I cannot find that chain. Please check the chain name you sent me.")
}
return nil
}
示例13: FindServiceDefinitionFile
func FindServiceDefinitionFile(name string) string {
return util.GetFileByNameAndType("services", name)
}
示例14: EditAction
func EditAction(do *definitions.Do) error {
actDefFile := util.GetFileByNameAndType("actions", do.Name)
logger.Infof("Editing Action =>\t\t%s\n", actDefFile)
do.Result = "success"
return Editor(actDefFile)
}
示例15: EditAction
func EditAction(do *definitions.Do) error {
actDefFile := util.GetFileByNameAndType("actions", do.Name)
log.WithField("file", actDefFile).Info("Editing action")
do.Result = "success"
return Editor(actDefFile)
}