本文整理汇总了Golang中github.com/9seconds/ah/app/environments.Environment.GetBookmarkFileName方法的典型用法代码示例。如果您正苦于以下问题:Golang Environment.GetBookmarkFileName方法的具体用法?Golang Environment.GetBookmarkFileName怎么用?Golang Environment.GetBookmarkFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/9seconds/ah/app/environments.Environment
的用法示例。
在下文中一共展示了Environment.GetBookmarkFileName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListBookmarks
// ListBookmarks prints the list of bookmarks with their content
func ListBookmarks(env *environments.Environment) {
bookmarksFileInfos, err := env.GetBookmarksFileInfos()
if err != nil {
utils.Logger.Panic(err)
}
maxLength := 1
for _, fileInfo := range bookmarksFileInfos {
name := fileInfo.Name()
if len(name) > maxLength {
maxLength = len(name)
}
}
template := "%-" + strconv.Itoa(maxLength) + "s %s\n"
utils.Logger.WithFields(logrus.Fields{
"template": template,
}).Info("Calculated template to print")
for _, fileInfo := range bookmarksFileInfos {
fileName := fileInfo.Name()
content, err := ioutil.ReadFile(env.GetBookmarkFileName(fileName))
if err != nil {
utils.Logger.WithFields(logrus.Fields{
"filename": fileName,
"error": err,
}).Warn("Cannot read a content of the file so skip")
continue
}
fmt.Printf(template, fileName, string(content))
}
}
示例2: ExecuteBookmark
// ExecuteBookmark executes command by its bookmark name.
func ExecuteBookmark(name string, interactive bool, pseudoTTY bool, env *environments.Environment) {
content, err := ioutil.ReadFile(env.GetBookmarkFileName(name))
if err != nil {
utils.Logger.Panic("Unknown bookmark")
}
execute(string(content), env.Shell, interactive, pseudoTTY)
}
示例3: Bookmark
// Bookmark implements "b" (bookmark) command.
func Bookmark(commandNumber int, bookmarkAs string, env *environments.Environment) {
if commandNumber < 0 {
utils.Logger.Panic("Command number should be >= 0")
}
commandsKeeper, err := historyentries.GetCommands(historyentries.GetCommandsAll, nil, env)
if err != nil {
utils.Logger.Panic(err)
}
commands := commandsKeeper.Result().([]historyentries.HistoryEntry)
if len(commands) <= commandNumber {
utils.Logger.Panic("Command number does not exist")
}
command := commands[commandNumber-1]
filename := env.GetBookmarkFileName(bookmarkAs)
file, err := os.Create(filename)
if err != nil {
utils.Logger.Panicf("Cannot create bookmark %s: %v", filename, err)
}
defer file.Close()
file.WriteString(command.GetCommand())
}
示例4: RemoveBookmarks
// RemoveBookmarks removes the list of bookmarks from the storage.
func RemoveBookmarks(bookmarks []string, env *environments.Environment) {
for _, bookmark := range bookmarks {
utils.RemoveWithLogging(env.GetBookmarkFileName(bookmark))
}
}