devenv

package module
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

devenv

devenv is a tool to manage projects containing multiple git repositories. With a config you can setup all repositories with one command and even work with the local repositories as if they where one ( eg creating branches in all referenced projects) using the shell.

Go Report Card codebeat badge

Prerequisites

You have to have a working git commandline installation.

Known caveats

Developed and mostly tested under Linux. OSX and Windows are currently not thoroughly tested.

Commands to be executed before a bash is called is unsupported on Windows.

A shell must be configured for Windows.

Main configuration

There are two main configuration options:

  1. basepath
  2. configpath

Those values can either be set in your home directory in a .devenv.[yaml,toml,json] file, in the current directory or as environment variables.

A sample yaml file looks like this:

---

basepath: /dev/src
configpath: /home/user/.devenv

This project uses viper for configuration and commandline argument handling.

basepath

This is the path in which projects are created. E setup project creates a folder within and checks out the connected repositories relative to that directory.

configpath

Where to store the project specific configurations.

Project configuration

The project configuration contains references to the repositories and basic settings for the environment:

  1. name
  2. repositories
  3. env
  4. shell
  5. commands

A valid project configuration looks like this:

---

name: devenv
repositories:
  - name: devenv
    url: git@github.com:sascha-andres/devenv.git
    path: src/devenv
processes:
  shell: bash
  commands:
    - echo Hello
  env:
    VAR: VALUE
name

Name must be a unique name for your project. It is used to identify the project configuration in devenv calls.

repositories

A list of repositories. Each repository must provide the following information:

  1. name
  2. path
  3. url

A valid repository entry looks like this:

name: devenv
path: src/devenv
url: git@github.com:sascha-andres/devenv.git
name

Is used to identify the repository for operations specific to one repository

path

A relative path where the repository is cloned to

url

Remote url to the repository

External process configuration
env

Key value pairs that are added to the shell and git processes

shell

Executable fot the shell. If you want to use the fish shell in one project as opposed to your default shell specify here.

shellarguments

Passed to the shell as arguments

commands

Commands to execute before the shell is called.

Variables

Each environment variable known to the devenv process can be access as go standard template in the following places:

  • commands
  • shell
  • shell-arguments
  • Environment variables for processes

Values in env override the environment variables. An additional variable called ENV_DIRECTORY is provided containing the path to the environment.

While technically possible to inject references this is not supported!

Commands

Commands are top level commands to work with devenv itself. The following commands exist:

  • add
  • shell
  • clean
  • setup
  • list
Interactive shell

Breaking change in 1.3.0

Call devenv -- <environment> to start the interactive shell. With devenv shell <environment> the bash shell or configured shell will be called.

For commands see In-App shell

list

List all repositories in an environment:

devenv list <environment name>
add

Create a new project stub:

devenv add project

This will create a new configuration in your configuration directory.

shell

Open a system shell in the project directory with environment variables preconfigured.

You might add a --force flag to remove even though uncommitted changes exist.

Please make sure you synced with your remotes!!

clean

Remove project from basepath. Checks for uncommitted changes.

fetch
Info
Aliases f
Description Run a git fetch on all repositories
setup

Create project directory and clone all referenced projects. If your definition contains disabled projects, those will not be pulled.

version

Call to have the version printed out

In-App shell

The in app shell provides easy methods to work with your git repositories. Non aliases are part of autocompletion

shell command
Info
Aliases none
Description Opens an operating system shell at the project root directory

Call with

shell

addrepo command
Info
Aliases none
Description Will ask for the required values of a repository and if cloning is successful saves the new repository to the project configuration

Call with

addrepo

Required information:

  • name
  • path
  • url
branch
Info
Aliases br
Description Will switch to the specified branch for each repository
If the branch does not exist, it will be created

Call with

branch <name>

You can add any number of additional arguments as long as they are valid arguments to git checkout

Required information:

  • name
delrepo command
Info
Aliases none
Description Will ask for the name of a repository and remove it from project when there are no changes

Call with

delrepo <name>

Required information:

  • name
log command
Info
Aliases l
Description Prints out the last ten commits decorated for each repository

Call with

log
pull command
Info
Aliases <
Description Executes a pull for each repository

Call with

pull

You can add any number of additional arguments as long as they are valid arguments to git pull

push command
Info
Aliases >
Description Executes a push for each repository

Call with

push

You can add any number of additional arguments as long as they are valid arguments to git push

status command
Info
Aliases st
Description Prints the status of each referenced repository

Call with

status

You can add any number of additional arguments as long as they are valid arguments to git status

scan
Info
Description Iterates over the directories within the projects path searching for git repositories

Call with

scan
rename
Info
Description Allow renaming an environment

Call with

rename [old] -> [new]
Repository commands

Repository commands take the name of a repository as they work on a single repository and not on every referenced repository.

They are prefixed with repo which can be shortened to r.

The following commands are available for a single repository:

  • branch
  • commit
  • log
  • merge
  • pull
  • push
  • status
  • pin
  • unpin
  • shell
  • fetch
fetch

Runs a git fetch on the repository repositories

Info
Aliases f
Description Run a git fetch on the repository
shell command
Info
Aliases none
Description Opens an operating system shell at the project root directory

Call with

repo shell

pin

Stores the current commit to the configuration.

  • Most actions are not performed on pinned repositories
  • On setup, a checkout on the specific commit will be done.

Call with

repo <name> pin
unpin

If pinned the repository will be unpinned and the specified branch will be checked out

Call with

repo <name> unpin <branch>
branch
Info
Aliases br
Description Will switch to the specified branch for each repository
If the branch does not exist, it will be created

Call with

repo <name> branch <name-of-branch>

You can add any number of additional arguments as long as they are valid arguments to git checkout

Required information:

  • name
  • name-of-branch
log command
Info
Aliases l
Description Prints out the log for the repository

Call with

repo <name> log

Required information:

  • name
merge command
Info
Aliases none
Description Merge a branch

Call with

repo <name> merge <branch-name>

You can add any number of additional arguments as long as they are valid arguments to git merge

Required information:

  • name
pull command
Info
Aliases <
Description Executes a pull

Call with

repo <name> pull

You can add any number of additional arguments as long as they are valid arguments to git pull

Required information:

  • name
push command
Info
Aliases >
Description Executes a push for repository

Call with

repo <name> push

You can add any number of additional arguments as long as they are valid arguments to git push

Required information:

  • name
status command
Info
Aliases st
Description Prints the status of repository

Call with

repo <name> status

You can add any number of additional arguments as long as they are valid arguments to git status

Required information:

  • name

Code of conduct

You can find the code of conduct here, taken from Contributor Covenant

History

Version Description
1.6.0 use go.mod
allow rename of environment
script management
refactoring of file layout
1.5.1 Reload list of repositories for autocomplete after adding a new one
1.5.0 Disabled repositories are not cloned
Disable/Enable added to autocomplete
github.com/pkg/erros
v1.4.0 Added shell command for interactive shell
v1.3.1 Fix for push command
v1.3.0 scan for repositories
pin repositories
shell command calls bash/os shell
-- calls interactive shell
v1.2.0 Make log parameters configurable
Refactorings
v1.1.1 Fix for branch detection
Refactorings
v1.1.0 Completion for shell
Command arguments for shell
Variables
v1.0.1 Enable/Disable repository
v1.0.0 Initial version

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProjectIsCreated

func ProjectIsCreated(projectName string) bool

ProjectIsCreated checks whether project is checked out

func PullConfiguration added in v1.6.0

func PullConfiguration() error

PullConfiguration gets the latest commit from remote repository

func PushConfiguration added in v1.6.0

func PushConfiguration() error

PushConfiguration puts the latest commit to remote repository

Types

type EnvironmentConfiguration

type EnvironmentConfiguration struct {
	Name                 string                                  `yaml:"name"`
	Repositories         []RepositoryConfiguration               `yaml:"repositories"`
	ProcessConfiguration EnvironmentExternalProcessConfiguration `yaml:"processes"`
}

EnvironmentConfiguration contains information about the project

func (*EnvironmentConfiguration) GetEnvironment added in v1.1.1

func (ev *EnvironmentConfiguration) GetEnvironment() ([]string, error)

GetEnvironment returns the templated env vars

func (*EnvironmentConfiguration) GetReplacedEnvironment added in v1.1.0

func (ev *EnvironmentConfiguration) GetReplacedEnvironment() (map[string]string, error)

GetReplacedEnvironment provides a way to get the environment variables with replaced values

func (*EnvironmentConfiguration) GetRepository

func (ev *EnvironmentConfiguration) GetRepository(repoName string) (int, *RepositoryConfiguration)

GetRepository returns a repository with given name

func (*EnvironmentConfiguration) GetShell added in v1.1.1

func (ev *EnvironmentConfiguration) GetShell() (string, []string, error)

GetShell returns the shell executable with template applied

func (*EnvironmentConfiguration) GetVariables added in v1.1.0

func (ev *EnvironmentConfiguration) GetVariables() (map[string]string, error)

GetVariables returns variable map for environment

func (*EnvironmentConfiguration) LoadFromFile

func (ev *EnvironmentConfiguration) LoadFromFile(path string) error

LoadFromFile takes a YAML file and unmarshals its data

func (*EnvironmentConfiguration) RepositoryExists

func (ev *EnvironmentConfiguration) RepositoryExists(repoName string) bool

RepositoryExists returns true if a repository is configured in environment

func (*EnvironmentConfiguration) SaveToFile

func (ev *EnvironmentConfiguration) SaveToFile(path string) error

SaveToFile takes the config and saves to disk

func (*EnvironmentConfiguration) StartShell

func (ev *EnvironmentConfiguration) StartShell() error

StartShell executes configured shell or default shell (sh)

func (*EnvironmentConfiguration) StartShellForSubdirectory added in v1.4.0

func (ev *EnvironmentConfiguration) StartShellForSubdirectory(subdirectory string) error

StartShellForSubdirectory executes configured shell or default shell (sh) within a specified subdirectory

type EnvironmentExternalProcessConfiguration added in v1.3.0

type EnvironmentExternalProcessConfiguration struct {
	Environment    map[string]string `yaml:"env"`
	Shell          string            `yaml:"shell"`
	ShellArguments []string          `yaml:"shell-arguments"`
	Commands       []string          `yaml:"commands"`
}

EnvironmentExternalProcessConfiguration contains configuration in use with external processes

type RepositoryConfiguration

type RepositoryConfiguration struct {
	Name     string `yaml:"name"`
	Path     string `yaml:"path"`
	URL      string `yaml:"url"`
	Disabled bool   `yaml:"disabled"`
	Pinned   string `yaml:"pinned"`
}

RepositoryConfiguration contains information about linked repositories

func (RepositoryConfiguration) ToString added in v1.3.0

func (rc RepositoryConfiguration) ToString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL