示例#1
0
文件: init.go 项目: disorganizer/brig
// NewRepository creates a new repository at filesystem level
// and returns a Repository interface
func NewRepository(ID, pwd, folder string) (*Repository, error) {
	absFolderPath, err := filepath.Abs(folder)
	if err != nil {
		return nil, err
	}

	if _, err = os.Stat(absFolderPath); os.IsExist(err) {
		return nil, err
	}

	if err := createRepositoryTree(absFolderPath); err != nil {
		return nil, err
	}

	brigPath := filepath.Join(absFolderPath, ".brig")
	if err := createShadowFile(brigPath, ID, pwd); err != nil {
		return nil, err
	}

	cfg := config.CreateDefaultConfig()

	configDefaults := map[string]interface{}{
		"repository.id": ID,
		"ipfs.path":     filepath.Join(brigPath, "ipfs"),
	}

	for key, value := range configDefaults {
		if err = cfg.Set(key, value); err != nil {
			return nil, err
		}
	}

	if err := initIntoGlobal(brigPath, cfg); err != nil {
		return nil, err
	}

	configPath := filepath.Join(brigPath, "config")
	if _, err := config.SaveConfig(configPath, cfg); err != nil {
		return nil, err
	}

	return loadRepository(pwd, absFolderPath)
}
示例#2
0
func handleConfigSet(ctx *cli.Context, cfg *config.Config) error {
	key := ctx.Args().First()
	value := ctx.Args().Get(1)
	if err := cfg.Set(key, value); err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Could not set %s: %v", key, err),
		}
	}

	folder := repo.GuessFolder()
	if _, err := repoconfig.SaveConfig(filepath.Join(folder, ".brig", "config"), cfg); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Could not save config: %v", err),
		}
	}
	return nil
}