wami

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 20 Imported by: 0

README

wami

Build Test Go Report Card codecov Go Reference

wami ("What Are My Imports?") is a tool for Go projects that analyzes imports and their aliases. It offers a wide range of options, filters, and output formats, making it easy to integrate with other tools.

Table of Contents

Install

go install github.com/ravsii/wami/cmd/wami@latest

Usage

NAME:
   wami - What are my imports? (wami) is a cli for import analisys for go apps.

USAGE:
   wami [global options] [arguments...]

GLOBAL OPTIONS:
   --aliases-only, -a          only output imports that have aliases. Note: all imports will be parsed anyways, for a total amount of usages
   --format string, -f string  output format (text, text-colored, json, csv) (default: "text-colored")
   --ignore regexp             regexp to ignore import paths
   --ignore-alias regexp       regexp to ignore import aliases
   --ignore-blank              ignore blank imports (e.g., '_ fmt')
   --ignore-dot                ignore dot imports (e.g., '. fmt')
   --ignore-same               ignore imports using the same alias as the original package (e.g., 'fmt fmt')
   --include regexp            regexp to include import paths
   --include-alias regexp      regexp to include import aliases
   --max uint                  maximum amount of usages to appear in the output (inclusive) (default: 0)
   --min uint                  minimal amount of usages to appear in the output (inclusive) (default: 0)
   --recursive, -r             enables recursive walking for ALL paths. If disabled, only paths ending with '...' are treated as recursive
   --help, -h                  show help

Outputs

Here’s an example output in multiple formats, generated from the kubernetes repository - one of the largest Go projects:

> wami <path> --min 300 --max 350
Text output
Show example
k8s.io/client-go/kubernetes/scheme: 349 total usages
 ├ 210 usages as scheme
 ├ 13 usages as clientscheme
 ├ 6 usages as clientsetscheme
 ├ 3 usages as k8sscheme
 ├ 2 usages as clientgoscheme
 ├ 1 usages as cgoscheme
 ├ 1 usages as clientgokubescheme
 ├ 1 usages as kubernetesscheme
 └ 1 usages as typedscheme
syscall: 345 total usages
regexp: 342 total usages
 └ 1 usages as re
k8s.io/apimachinery/pkg/api/equality: 320 total usages
 ├ 215 usages as apiequality
 └ 62 usages as equality
github.com/onsi/gomega: 317 total usages
 ├ 8 usages as .
 └ 2 usages as o
JSON output
Show example
[
  {
    "path": "k8s.io/client-go/kubernetes/scheme",
    "count": 349,
    "aliases": [
      {
        "count": 210,
        "name": "scheme"
      },
      {
        "count": 13,
        "name": "clientscheme"
      },
      {
        "count": 6,
        "name": "clientsetscheme"
      },
      {
        "count": 3,
        "name": "k8sscheme"
      },
      {
        "count": 2,
        "name": "clientgoscheme"
      },
      {
        "count": 1,
        "name": "cgoscheme"
      },
      {
        "count": 1,
        "name": "clientgokubescheme"
      },
      {
        "count": 1,
        "name": "kubernetesscheme"
      },
      {
        "count": 1,
        "name": "typedscheme"
      }
    ]
  },
  {
    "path": "syscall",
    "count": 345
  },
  {
    "path": "regexp",
    "count": 342,
    "aliases": [
      {
        "count": 1,
        "name": "re"
      }
    ]
  },
  {
    "path": "k8s.io/apimachinery/pkg/api/equality",
    "count": 320,
    "aliases": [
      {
        "count": 215,
        "name": "apiequality"
      },
      {
        "count": 62,
        "name": "equality"
      }
    ]
  },
  {
    "path": "github.com/onsi/gomega",
    "count": 317,
    "aliases": [
      {
        "count": 8,
        "name": "."
      },
      {
        "count": 2,
        "name": "o"
      }
    ]
  }
]
CSV output

Alias column has the following format:

"<count1>,<alias1>;<count2>,<alias2>;..."
Show example
import,count,aliases
k8s.io/client-go/kubernetes/scheme,349,"210,scheme;13,clientscheme;6,clientsetscheme;3,k8sscheme;2,clientgoscheme;1,cgoscheme;1,clientgokubescheme;1,kubernetesscheme;1,typedscheme"
syscall,345,
regexp,342,"1,re"
k8s.io/apimachinery/pkg/api/equality,320,"215,apiequality;62,equality"
github.com/onsi/gomega,317,"8,.;2,o"

Documentation

Index

Constants

View Source
const (
	FormatText        = "text"
	FormatTextColored = "text-colored"
	FormatJson        = "json"
	FormatCsv         = "csv"
)

Variables

This section is empty.

Functions

func NewStorage

func NewStorage(opts Options) importStorage

func ParseFiles

func ParseFiles(opts Options) (*importStorage, error)

func Run

func Run(args []string)

Types

type Alias

type Alias struct {
	Count uint   `json:"count"`
	Name  string `json:"name"`
}

type CsvPrinter

type CsvPrinter struct{}

func (*CsvPrinter) Print

func (t *CsvPrinter) Print(w io.Writer, imports []OutputImports) error

type JsonPrinter

type JsonPrinter struct{}

func (JsonPrinter) Print

func (JsonPrinter) Print(w io.Writer, imports []OutputImports) error

type Options

type Options struct {
	Paths []string

	// options related to parsing
	Parse ParseOptions

	// options related to Output
	Output OutputOptions
}

type OutputImports

type OutputImports struct {
	Path    string  `json:"path"`
	Count   uint    `json:"count"`
	Aliases []Alias `json:"aliases,omitempty"`
}

type OutputOptions

type OutputOptions struct {
	AliasesOnly bool
	Format      string
	Max         uint
	Min         uint
}

type ParseOptions

type ParseOptions struct {
	Recursive bool

	Include      *regexp.Regexp
	IncludeAlias *regexp.Regexp
	Ignore       *regexp.Regexp
	IgnoreAlias  *regexp.Regexp

	IgnoreDot   bool
	IgnoreBlank bool
	IgnoreSame  bool
}

type Printer

type Printer interface {
	// Print should output data into w.
	Print(w io.Writer, data []OutputImports) error
}

type TextPrinter

type TextPrinter struct{ Colored bool }

func (*TextPrinter) Print

func (t *TextPrinter) Print(w io.Writer, imports []OutputImports) error

Directories

Path Synopsis
cmd
wami command

Jump to

Keyboard shortcuts

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