Пример #1
0
func run() error {
	if len(os.Args) <= 1 {
		return errors.New("Usage: tldr <command>")
	}

	usr, err := user.Current()
	if err != nil {
		return err
	}
	if usr.HomeDir == "" {
		return errors.New("Can't load user's home folder path")
	}

	var repository entity.Repository
	repository = remote.NewRemoteRepository(remoteAddress)
	repository = cache.NewFileSystemCacheRepository(repository, path.Join(usr.HomeDir, ".tldr"), time.Hour*24)
	repository = tldr.NewIndexCheckerRepository(repository)

	cmd := os.Args[1]
	platform := runtime.GOOS
	switch platform {
	case "darwin":
		platform = "osx"
	}

	var page entity.Page
	for _, platform := range []string{platform, "common"} {
		page, err = repository.Page(cmd, platform)
		if err != nil {
			continue
		}
		defer page.Close()
		fmt.Println(tldr.Render(page.Reader()))
		return nil
	}
	return err
}
Пример #2
0
func (t *testServer) Intercept(test func()) {
	server := httptest.NewServer(t)
	defer server.Close()
	repository = remote.NewRemoteRepository(server.URL)
	test()
}