Coder Social home page Coder Social logo

mwiater / golangpeekr Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 107 KB

Peer into the source code for a high-level view of how a package is constructed. This is a personal CLI tool built in Go, using Cobra, Viper, and the AST package.

Home Page: https://blog.stackademic.com/the-anatomy-of-go-code-dissecting-with-the-go-ast-package-325a43a1618c

License: Other

Go 100.00%
ast cobra go viper

golangpeekr's Introduction

golangpeekr

A repository for common, reusable functions

Application

To see a list of available functions in the package as a demo, just: go run .

This will print out all of the exported functions with comments, arguments, and return types, e.g.:

Functions in the 'helpers' package:

[ slices ]

  // SliceContains checks if an item is present in the given slice.
  SliceContains(slice []T, item T) bool

  // SliceIntersection returns a new slice containing the common elements of two slices.
  SliceIntersection(slice1 []T, slice2 []T) []T

[ terminal ]

  // ClearTerminal clears the terminal screen based on the operating system.
  ClearTerminal() error

  // TerminalColor prints the given string to the terminal in the color corresponding to the error level
  TerminalColor(message string, level ErrorLevel)

  // TerminalInfo prints collects various information about the current terminal.
  TerminalInfo() (*Terminal, error)


Structs in the 'helpers' package:

[ terminal ]

  // Terminal struct holds information about the user's terminal environment.
  Height int
  Width int
  OutputType string
  NumberOfSupportedColors int
  TERM string
  SHELL string
  COLORTERM string

CLI

Linux

If your source machine is linux, use appropriate forward slashes and build natively: Build: go build -o bin/peekr Run: ./bin/peekr --help

The Peekr command by itself doesn't do anything at the moment. Please
see the Peekr list subcommand via: 'peekr list --help'

Usage:
  peekr [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  list        List the functions and structs within a package.

Flags:
  -d, --directory string   Absolute path of directory to scan.
  -h, --help               help for peekr
  -p, --package string     Name of package to scan.

Use "peekr [command] --help" for more information about a command.

Run: ./bin/peekr list --help

Peek into the source code for a high-level view of how a package
is constructed. By default, the 'list' command will print both
functions and structs in the specified package. You can filter
out one or the other by specifying '-s' and '-f' flags.

Usage:
  peekr list [flags]

Flags:
  -f, --functions   Only list package functions.
  -h, --help        help for list
  -s, --structs     Only list package structs.

Global Flags:
  -d, --directory string   Absolute path of directory to scan.
  -p, --package string     Name of package to scan.

Windows

If your source machine is Windows, use appropriate backward slashes and build natively: Build: go build -o bin\peekr.exe Run: bin\peekr.exe --help

CLI Options / flags

Show both functions and structs:

  • ./bin/peekr list -d "/home/matt/projects/golangpeekr" -p "helpers"
  • ./bin/peekr list -sf -d "/home/matt/projects/golangpeekr" -p "helpers"

Show functions only:

  • ./bin/peekr list -f -d "/home/matt/projects/golangpeekr" -p "helpers"

Show structs only:

  • ./bin/peekr list -s -d "/home/matt/projects/golangpeekr" -p "helpers"

Tests

go install gotest.tools/gotestsum@latest

gotestsum --format=testname


EMPTY .
EMPTY cmd
EMPTY config
EMPTY helpers
PASS peekr.TestExtractFuncParams/No_params (0.00s)
PASS peekr.TestExtractFuncParams/One_param (0.00s)
PASS peekr.TestExtractFuncParams/Multiple_params (0.00s)
PASS peekr.TestExtractFuncParams/Unnamed_params (0.00s)
PASS peekr.TestExtractFuncParams (0.00s)
PASS peekr.TestExtractFuncResults/No_results (0.00s)
PASS peekr.TestExtractFuncResults/One_result (0.00s)
PASS peekr.TestExtractFuncResults/Multiple_results (0.00s)
PASS peekr.TestExtractFuncResults/Named_results (0.00s)
PASS peekr.TestExtractFuncResults (0.00s)
PASS peekr.TestExprToString/Identifier (0.00s)
PASS peekr.TestExprToString (0.00s)
PASS peekr.TestCommentify/Single_line_comment (0.00s)
PASS peekr.TestCommentify/Multi-line_comment (0.00s)
PASS peekr.TestCommentify/Empty_comment (0.00s)
PASS peekr.TestCommentify (0.00s)
PASS peekr (cached)

DONE 16 tests in 0.167s

golangpeekr's People

Contributors

mwiater avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.