{"id":26493271,"url":"https://github.com/bblfsh/tools","last_synced_at":"2025-03-20T09:51:53.498Z","repository":{"id":57579445,"uuid":"92750537","full_name":"bblfsh/tools","owner":"bblfsh","description":"Miscellaneous tools to work with Babelfish UAST.","archived":false,"fork":false,"pushed_at":"2019-11-06T17:01:27.000Z","size":165,"stargazers_count":10,"open_issues_count":3,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-06-20T14:23:05.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bblfsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2017-05-29T15:06:02.000Z","updated_at":"2024-06-20T14:23:05.012Z","dependencies_parsed_at":"2022-09-26T19:12:14.246Z","dependency_job_id":null,"html_url":"https://github.com/bblfsh/tools","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bblfsh%2Ftools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bblfsh%2Ftools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bblfsh%2Ftools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bblfsh%2Ftools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bblfsh","download_url":"https://codeload.github.com/bblfsh/tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244591490,"owners_count":20477709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-20T09:51:52.943Z","updated_at":"2025-03-20T09:51:53.485Z","avatar_url":"https://github.com/bblfsh.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babelfish Tools\n\n[![Build Status](https://travis-ci.org/bblfsh/tools.svg?branch=master)](https://travis-ci.org/bblfsh/tools)\n[![codecov](https://codecov.io/gh/bblfsh/tools/branch/master/graph/badge.svg)](https://codecov.io/gh/bblfsh/tools)\n\nLanguage analysis tools on top of Babelfish\n\n## Build\n\n```sh\ngo get -u -v -d github.com/bblfsh/tools/...\n```\n\nIf you want to build a docker image containing Babelfish Tools, run:\n\n`make build`\n\n## Usage\n\nBabelfish Tools provides a set of tools built on top of Babelfish, to\nsee which tools are supported, run:\n\n`bblfsh-tools --help`\n\nTo make use of any of these tools you need to have the Babelfish\nserver up and running. The easiest way to do so is through docker:\n\n`docker run --privileged -p 9432:9432 --name bblfsh bblfsh/server`\n\nLook at [bblfshd](https://github.com/bblfsh/bblfshd/) for more\ninformation.\n\nOnce you have a `bblfshd` running, you can use the dummy tool, which\nshould let you know if the connection with the server succeeded:\n\n`bblfsh-tools dummy path/to/source/code`\n\nIf the `bblfshd` instance is running at a different address, use the `address` parameter:\n\n`bblfsh-tools dummy --address location:port path/to/source/code`\n\nOnce the connection with the server is working fine, you can use any other\navailable tool in a similar way.\n\n### Available tools\n\nApart from the dummy tool, the following tools are currently provided:\n\n* cyclomatic: Parses a code file and prints its\n  [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity)\n* npath: Parses a code file and prints the\n  [npath complexity](https://pmd.github.io/pmd-5.7.0/pmd-java/xref/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityRule.html)\n  of its functions\n* tokenizer: Parses a code file and extracts and prints its tokens\n\n## How to add a new tool to Babelfish Tools\n\nAdding a new tool to Babelfish Tools involves two steps: implementing\nthe Tool interface and adding it as a command to the CLI interface.\n\n### Implementing the Tooler interface\n\nThe `Tooler` interface has a single method `Exec(*uast.Node) error`,\nthat is, a tool must implement a method called `Exec` that receives a\npointer to an UAST node and returns an optional `error`.\n\nIt's also convenient to create a new type for the new tool, to be used\nin the CLI interface command. In the simplest case, an empty struct\nwill do: `type Dummy struct{}`\n\n### Adding the new tool as a command to the CLI interface\n\nCreate a new file for the tool command in the `cmd/bblfsh-tools`\ndirectory.\n\nCreate a new type there for your tool. It should at least include\nCommon struct. If your tool will support additional parameters, add\nthem there. In the simplest case, it'd just be:\n\n```go\ntype Dummy struct {\n\tCommon\n}\n```\n\nImplement the\n[Commander interface](https://godoc.org/github.com/jessevdk/go-flags#Commander). There's\na helper common method `execute` that will provides a good default, in\nmost cases calling this method should be enough:\n\n```go\nfunc (c *Dummy) Execute(args []string) error {\n\treturn c.execute(args, tools.Dummy{})\n}\n```\n\nNote that `tools.Dummy{}` is the instance of the type that implements\nthe `Tooler` interface that we described in the previous section.\n\nAt this point, only adding the command to the parser is left. This is\ndone at `cmd/bblfsh-tools/main.go`:\n\n```go\nparser.AddCommand(\"dummy\", \"\", \"Run dummy tool\", \u0026Dummy{})\n```\n\nAnd that's it, rebuild and your new tool should be ready to use.\n\n## License\n\nGPLv3, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbblfsh%2Ftools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbblfsh%2Ftools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbblfsh%2Ftools/lists"}