Git Product home page Git Product logo

hardcodes's Introduction


hardcodes
hardcodes

extract strings from source code

hardcodes is a utility for searching strings hardcoded by developers in programs. It uses a modular tokenizer that can handle comments, any number of backslashes & nearly any syntax you throw at it.

Yes, it is designed to process any syntax and following languages are officially supported:

ada, applescript, c, c#, c++, coldfusion, golang, haskell, html, java, javascript,
jsp, lua, pascal, perl, php, powershell, python, ruby, scala, sql, swift, xml

Installation

with pip
pip3 install hardcodes
or build from source
git clone https://github.com/s0md3v/hardcodes && cd hardcodes && python3 setup.py install

Documentation

hardcodes is available as both a library as well as a command line program. The relevant documentation can be found below:

For Developers

The sample program below demonstrates usage of hardcodes library

from hardcodes import search

string = "console.log('hello there')"
result = search(string, lang="common", comments="parse")
print(result)
Output: ['hello there']

The arguments lang and comments are optional. Their use is explained below in the user documentation section.


For Users

cli.py provides a grep-like command line interface to hardcodes library. You will need to install the library first to use it.

Find strings in a file

python cli.py /path/to/file.ext

Find strings in a directory, recursively

python cli.py -r /path/to/dir

Hide paths from output

python cli.py -o /path/to/file.ext

Specify programming language

Specifying a language is optional and should be used only when the programming language of source is already known.

python cli.py -l 'golang' /path/to/file.go

Specify comment behaviour

With -c option, you can specify

  • ignore ignore the comments completely
  • parse parse the comments like code
  • string add comments to list of hardcoded strings

python cli.py -o /path/to/file.ext

Specify line numbers

With the -n, --line-numbers option, you can attach the line numbers where string occurred. This can be used to locate the line in code easily, or to use as input into a script that will modify the strings for you.

The line numbers are inserted between the file name, and string, also using ':' as a seperator. (See 'filter' example below).

Filter output by regular expression

With the -q, --query option, the output can be filtered by applying a regular expression (supplied on the command line) to the extracted string.

This can be used for specific tasks, such as changing all occurances of a product's name, or publisher.

python cli.py -l python -n -q "source code" cli.py

which gives the following output:

cli.py:12:specify programming language of source code
cli.py:13:include source code line numbers in output

hardcodes's People

Contributors

s0md3v avatar mpmansell avatar roushikk 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.