q

package module
v0.0.0-...-2d1bf66 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: MIT Imports: 17 Imported by: 2

README

q

q is a better way to do print statement debugging.

Type q.Q instead of fmt.Printf and your variables will be printed like this:

q output examples

Why is this better than fmt.Printf?

  • Faster to type
  • Pretty-printed vars and expressions
  • Easier to see inside structs
  • Doesn't go to noisy-ass stdout. It goes to $TMPDIR/$USER.q.
  • Pretty colors!

Basic Usage

import "q"
...
q.Q(a, b, c)

For best results, dedicate a terminal to tailing $TMPDIR/$USER.q while you work.

Install

git get github.com/bingoohuang/ngg/q@latest

Put these functions in your shell config. Typing qq or rmqq will then start tailing $TMPDIR/$USER.q.

qq() {
    clear

    logpath="$TMPDIR/$USER.q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi

    if [[ ! -f "$logpath" ]]; then
        echo 'Q LOG' > "$logpath"
    fi

    tail -100f -- "$logpath"
}

rmqq() {
    logpath="$TMPDIR/$USER.q"
    if [[ -z "$TMPDIR" ]]; then
        logpath="/tmp/q"
    fi
    if [[ -f "$logpath" ]]; then
        rm "$logpath"
    fi
    qq
}

You also can simply tail -f $TMPDIR/$USER.q, but it's highly recommended to use the above commands.

Haven't I seen this somewhere before?

Python programmers will recognize this as a Golang port of the q module by zestyping.

Ping does a great job of explaining q in his awesome lightning talk from PyCon 2013. Watch it! It's funny :)

ping's PyCon 2013 lightning talk

FAQ

Why q.Q?

It's quick to type and unlikely to cause naming collisions.

Is q.Q() safe for concurrent use?

Yes.

Documentation

Overview

Package q provides quick and dirty debugging output for tired programmers.

q.Q() is a fast way to pretty-print variables. It's easier than typing fmt.Printf("%#v", whatever). The output will be colorized and nicely formatted. The output goes to $TMPDIR/$USER.q, away from the noise of stdout.

q exports a single Q() function. This is how you use it:

import "q"
...
q.Q(a, b, c)

Index

Constants

This section is empty.

Variables

View Source
var (

	// CallDepth allows setting the number of levels runtime.Caller will
	// skip when looking up the caller of the q.Q function. This allows
	// the `q` package to be wrapped by a project-specific wrapping function,
	// which would increase the depth by at least one. It's better to not
	// include calls to `q.Q` in released code at all and scrub them before,
	// a build is created, but in some cases it might be useful to provide
	// builds that do include the additional debug output provided by `q.Q`.
	// This also allows the consumer of the package to control what happens
	// with leftover `q.Q` calls. Defaults to 2, because the user code calls
	// q.Q(), which calls getCallerInfo().
	CallDepth = 3
)

Functions

func AppendFile

func AppendFile(name string, data []byte, mode os.FileMode) error

AppendFile appends data to a file.

func D

func D(v ...interface{})

D pretty-prints the given arguments to the $TMPDIR/$USER.q log file when export Q=1

func MergeErrors

func MergeErrors(errors ...error) error

MergeErrors merges multiple errors into a single error.

func Q

func Q(v ...interface{})

Q pretty-prints the given arguments to the $TMPDIR/$USER.q log file.

func Quote

func Quote(s string) string

Quote returns a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line.

func QuoteCommand

func QuoteCommand(args []string) string

QuoteCommand returns a shell-escaped version of the slice of strings. The returned value is a string that can safely be used as shell command arguments.

Types

type MultiError

type MultiError []error

MultiError represents an error that aggregates multiple errors.

func (MultiError) Error

func (m MultiError) Error() string

Error implements the error interface for MultiError.

Directories

Path Synopsis
cmd
q
Package pretty provides pretty-printing for Go values.
Package pretty provides pretty-printing for Go values.

Jump to

Keyboard shortcuts

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