當前位置: 首頁>>代碼示例>>Golang>>正文


Golang config.Config類代碼示例

本文整理匯總了Golang中github.com/gsamokovarov/jump/config.Config的典型用法代碼示例。如果您正苦於以下問題:Golang Config類的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Config類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: updateCmd

func updateCmd(args cli.Args, conf *config.Config) {
	dir, err := os.Getwd()
	if len(args) == 0 && err != nil {
		cli.Exitf(1, "err: %s\n", err)
	} else {
		if dir, err = filepath.Abs(args.CommandName()); err != nil {
			cli.Exitf(1, "err: %s\n", err)
		}
	}

	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "err: %s\n", err)
	}

	if entry, found := entries.Find(dir); found {
		entry.UpdateScore()
	} else {
		entries = append(entries, *scoring.NewEntry(dir))
	}

	if err := conf.WriteEntries(entries); err != nil {
		cli.Exitf(1, "err: %s\n", err)
	}
}
開發者ID:svetliomihailov,項目名稱:jump,代碼行數:25,代碼來源:chdir.go

示例2: hintCmd

func hintCmd(args cli.Args, conf *config.Config) {
	var hints scoring.Entries

	term := args.CommandName()
	smart := args.Has("--smart")

	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "%s\n", err)
	}

	if len(term) == 0 {
		// We usually keep them reversely sort to optimize the fuzzy search.
		sort.Sort(sort.Reverse(entries))

		hints = hintSmartSelect(entries, term, smart)
	} else {
		fuzzyEntries := scoring.NewFuzzyEntries(entries, term)

		hints = hintSmartSelect(&fuzzyEntries.Entries, term, smart)
	}

	for _, entry := range hints {
		cli.Outf("%s\n", entry.Path)
	}
}
開發者ID:NJichev,項目名稱:jump,代碼行數:26,代碼來源:hint.go

示例3: topCmd

func topCmd(args cli.Args, conf *config.Config) {
	entries, err := conf.ReadEntries()
	if err != nil {
		cli.Exitf(1, "%s\n", err)
	}

	// We usually keep them reversely sort to optimize the fuzzy search.
	sort.Sort(sort.Reverse(entries))

	for _, entry := range entries {
		cli.Outf("%s\n", entry.Path)
	}
}
開發者ID:svetliomihailov,項目名稱:jump,代碼行數:13,代碼來源:top.go

示例4: cdCmd

func cdCmd(args cli.Args, conf *config.Config) {
	term := args.CommandName()
	entries, err := conf.ReadEntries()

	if err != nil {
		cli.Exitf(1, "%s\n", err)
	}

	// If an auto-completion triggered a full path, just go there.
	if filepath.IsAbs(term) {
		cli.Outf("%s\n", term)
		return
	}

	index, search := 0, conf.ReadSearch()

	// If we happen to match the last term, e.g. j is called with no
	// arguments then jump to the previous search.
	if len(term) == 0 {
		term, index = search.Term, search.Index+1
	}

	fuzzyEntries := scoring.NewFuzzyEntries(entries, term)
	for {
		if entry, empty := fuzzyEntries.Select(index); !empty {
			// Remove the entries that no longer exists.
			if _, err := os.Stat(entry.Path); os.IsNotExist(err) {
				entries.Remove(entry.Path)
				conf.WriteEntries(entries)

				index++
				continue
			}

			// Jump to the next entry, if the jump is going to land on the
			// current directory.
			if cwd, err := os.Getwd(); err == nil && entry.Path == cwd {
				index++
				continue
			}

			cli.Outf("%s\n", entry.Path)
			conf.WriteSearch(term, index)
		}

		break
	}
}
開發者ID:NJichev,項目名稱:jump,代碼行數:48,代碼來源:cd.go


注:本文中的github.com/gsamokovarov/jump/config.Config類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。