当前位置: 首页>>代码示例>>Golang>>正文


Golang Environment.GetBookmarkFileName方法代码示例

本文整理汇总了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))
	}
}
开发者ID:9seconds,项目名称:ah,代码行数:35,代码来源:list_bookmarks.go

示例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)
}
开发者ID:9seconds,项目名称:ah,代码行数:9,代码来源:execute.go

示例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())
}
开发者ID:9seconds,项目名称:ah,代码行数:25,代码来源:bookmark.go

示例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))
	}
}
开发者ID:9seconds,项目名称:ah,代码行数:6,代码来源:remove_bookmarks.go


注:本文中的github.com/9seconds/ah/app/environments.Environment.GetBookmarkFileName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。