gosumwhy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(g *Graph, out io.Writer)

List writes on 'out' the list of all modules that appear in the graph 'g', and for each module the list of all versions mentioned in that graph.

func Path

func Path(g *Graph, targets []string, options *Options) error

Path searches for a path from the root module of 'g' to each of the modules mentioned in 'targets'. The path for each target is written to 'options.Out'. If 'options.AllVersions' is set: for each module listed in 'targets', a path to each version listed in graph 'g' for that module is written to 'out'. Otherwise: for each module+version listed in targets, a dependency path to that specific module+version is written to 'out'. A module can be specified either with a specific version (e.g: rsc.io/quote@v3.1.0) or without (e.g: rsc.io/quote). In the latter case: the newest version for that module is targeted.

Example
// fake reading the module graph for 'rsc.io/quote' from stdin:
stdin := strings.NewReader(`rsc.io/quote rsc.io/quote/v3@v3.0.0
	rsc.io/quote rsc.io/sampler@v1.3.0
	rsc.io/quote/v3@v3.0.0 rsc.io/smpler@v1.3.0
	rsc.io/sampler@v1.3.0 golang.org/x/text@v.0.0-20170915032832-14c0d48ead0c`)

gr, _ := readGraphFrom(stdin)

// search for a path to one or more specific modules, with default options:
Path(gr, []string{"rsc.io/sampler@v1.3.0", "golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c"}, nil)
Output:

----- rsc.io/sampler@v1.3.0
rsc.io/quote
rsc.io/sampler@v1.3.0
----- golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
rsc.io/quote
rsc.io/sampler@v1.3.0
golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c
Example (Allv)
// fake reading the module graph for 'filippo.io/age' (v1.1.0-rc.1) from stdin:
stdin := strings.NewReader(`filippo.io/age filippo.io/edwards25519@v1.0.0-rc.1
	filippo.io/age golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5
	filippo.io/age golang.org/x/sys@v0.0.0-20210903071746-97244b99971b
	filippo.io/age golang.org/x/term@v0.0.0-20210615171337-6886f2dfbf5b
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/net@v0.0.0-20210226172049-e18ecbb05110
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/text@v0.3.3
	golang.org/x/term@v0.0.0-20210615171337-6886f2dfbf5b golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
	`)

gr, _ := readGraphFrom(stdin)

// search for a path to *each version* of a module:
Path(gr, []string{"golang.org/x/sys"}, &Options{AllVersions: true})

// two dependency paths are printed, to show why two distinct version of 'golang.org/x/sys'
// are present in the graph :
Output:

----- golang.org/x/sys@v0.0.0-20210903071746-97244b99971b
filippo.io/age
golang.org/x/sys@v0.0.0-20210903071746-97244b99971b
----- golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
filippo.io/age
golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5
golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
Example (Most_recent)
// fake reading the module graph for 'filippo.io/age' (v1.1.0-rc.1) from stdin:
stdin := strings.NewReader(`filippo.io/age filippo.io/edwards25519@v1.0.0-rc.1
	filippo.io/age golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5
	filippo.io/age golang.org/x/sys@v0.0.0-20210903071746-97244b99971b
	filippo.io/age golang.org/x/term@v0.0.0-20210615171337-6886f2dfbf5b
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/net@v0.0.0-20210226172049-e18ecbb05110
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/term@v0.0.0-20201126162022-7de9c90e9dd1
	golang.org/x/crypto@v0.0.0-20210817164053-32db794688a5 golang.org/x/text@v0.3.3
	golang.org/x/term@v0.0.0-20210615171337-6886f2dfbf5b golang.org/x/sys@v0.0.0-20210615035016-665e8c7367d1
	`)

gr, _ := readGraphFrom(stdin)

// search for a path to the most recent version of a module (no specific version named):
Path(gr, []string{"golang.org/x/sys"}, nil)
Output:

----- golang.org/x/sys@v0.0.0-20210903071746-97244b99971b
filippo.io/age
golang.org/x/sys@v0.0.0-20210903071746-97244b99971b

func RunCmd

func RunCmd(inGraph io.Reader, args []string, options *Options) error

RunCmd applies the actions described in 'args' to the graph which can be read from 'inGraph'. 'inGraph' is expected to present a dependency graph, in the same format as the output of 'go mod graph'.

Types

type Graph

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

A Graph represents a dependency graph between go modules.

type Options

type Options struct {
	AllVersions bool

	Out io.Writer
	Err io.Writer
}

type Version

type Version struct {
	Path    string
	Version string `json:",omitempty"`
}

Version represents a module and its version. The struct is copy/pasted from golang.org/x/mod/module

func (Version) LessThan

func (v Version) LessThan(o Version) bool

LessThan compares two versions. If two

func (Version) String

func (v Version) String() string

String returns a string representation 'path@version'

Jump to

Keyboard shortcuts

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