p4

package module
v0.0.0-...-3ffa339 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 13 Imported by: 0

README

p4go

Go interface library to use Perforce Helix Core command line (p4 or p4.exe)

This is a fork of a fork that aims to fix a couple issues with the library, and extend it.

Note that I haven't updated any of the testing code, so the test-cases may be broken.

Documentation

Overview

Package p4 wraps the Perforce Helix Core command line.

It assumes p4 or p4.exe is in the PATH. It uses the p4 -G global option which returns Python marshalled dictionary objects.

p4 Python parsing module is based on: https://github.com/hambster/gopymarshal

Index

Constants

View Source
const (
	RawBytes outputType = iota
	RawString
	ParsedPython
	ParsedJson
)

Variables

View Source
var (
	ErrParse       = errors.New("invalid data")
	ErrUnknownCode = errors.New("unknown code")
)

Parse error

Functions

func ParseError

func ParseError(res map[interface{}]interface{}) error

ParseError - Turns p4 error messages into Go error's

func ParsedMapToDebugString

func ParsedMapToDebugString(inMapArr []map[interface{}]interface{}) (string, error)

ParsedMapToDebugString - Quick and dirty debug function to get parsed output as a printable string

func Unmarshal

func Unmarshal(buffer *bytes.Buffer) (ret interface{}, retErr error)

Unmarshal data serialized by python

func Unmarshal2

func Unmarshal2(buffer *bytes.Buffer) (ret interface{}, remainder []byte, retErr error)

Unmarshal2 data serialized by python, returning the unused portion.

Types

type Describe

type Describe struct {
	Code       string
	Change     string
	OldChange  string
	ChangeType string
	Client     string
	Desc       string
	Path       string
	Time       string
	Status     string
	User       string
	Jobs       []JobDescription
	Revisions  []Revision
}

Describe - Contains the output of a describe command

func RunDescribe

func RunDescribe(p4r Runner, args []string) (Describe, error)

RunDescribe - Runs the command: p4 describe args...

type Fix

type Fix struct {
	Code   string
	Change string
	Client string
	Date   string // seconds since epoch
	Job    string
	Status string
	User   string
}

Fix is a single fix from p4 fixes result

func RunFixes

func RunFixes(p4r Runner, args []string) ([]Fix, error)

RunFixes - Runs the command: p4 fixes args...

type Fixes

type Fixes []Fix

Fixes is all the results from p4 fixes

type JobDescription

type JobDescription struct {
	Job    string
	Status string
}

type P4

type P4 struct {
	// contains filtered or unexported fields
}

P4 - Environment for P4

func NewP4

func NewP4() *P4

NewP4 - Create and initialise a default P4 instance. Any commands invoked with this P4 instance will use default Perforce environment variables.

func NewP4Params

func NewP4Params(port string, user string, client string, workingDirectory string) *P4

NewP4Params - Create and initialise with params. Any commands invoked with this P4 instance will override the default Perforce environment variables.

func (*P4) Run

func (p4 *P4) Run(args []string) ([]byte, error)

Run - The most basic Run() command. All this does is run p4 with the supplied arguments, and then blocks before returning the combined output.

func (*P4) RunAndGetBytes

func (p4 *P4) RunAndGetBytes(args []string) ([]byte, error)

RunAndGetBytes - Runs a p4 command and returns its output as a []byte

func (*P4) RunAndGetString

func (p4 *P4) RunAndGetString(args []string) (string, error)

RunAndGetString - Runs a p4 command and returns its output as a string

func (*P4) RunAndParseFromJson

func (p4 *P4) RunAndParseFromJson(args []string) ([]map[interface{}]interface{}, error)

RunAndParseFromJson - Runs a p4 command with the -Mj flag, parses the output, and returns the output as a map.

func (*P4) RunAndParseFromPython

func (p4 *P4) RunAndParseFromPython(args []string) ([]map[interface{}]interface{}, error)

RunAndParseFromPython - Runs a p4 command with the -G flag, parses the output, and returns the output as a map.

func (*P4) Save

func (p4 *P4) Save(specName string, specContents map[string]string, args []string) ([]map[string]string, error)

Save - Runs p4 -i for specified spec, then returns result

func (*P4) SaveTxt

func (p4 *P4) SaveTxt(specName string, specContents map[string]string, args []string) (string, error)

SaveTxt - The Save() func doesn't work as it needs the data marshalled instead of map[string]string This is a quick fix, the real fix is writing a marshal() function or try using gopymarshal

type Revision

type Revision struct {
	Action    string
	Rev       string
	DepotFile string
	Type      string
	Digest    string
	FileSize  string
}

type Runner

type Runner interface {
	Run([]string) ([]map[interface{}]interface{}, error)
}

Runner - An interface to make testing p4 commands easier

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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