The duct program allows to wrap code formatters inside of a stdin to
stdout filter-like data flow. It wraps a code formatter, which accepts file
names as commands arguments instead of reading from standard input data stream,
inside of a standard Unix stdin to stdout filter-like data flow. Consult
the package documentation or see
Usage to see how it works.
Install the package to use the command-line duct to wrap code formatters
inside of a stdin to stdout filter-like data flow.
go install github.com/mdm-code/duct/cmd/duct@latestAlthough I don't really see the reason why one might want to do it, use the following command to add the package to an existing project.
go get github.com/mdm-code/ductType duct -h to get information and examples on how to use duct and get
some ideas on how to use it in your workflow.
This very basic example show how to wrap black, a code formatter for Python,
with duct to use it as if it was a regular Unix data filter. Here is a snippet:
duct black -l 79 <<EOF
from typing import (
Protocol
)
class Sized(Protocol):
def __len__(self) -> int: ...
def print_size(s: Sized) -> None: len(s)
class Queue:
def __len__(self) -> int: return 10
q = Queue(); print_size(q)
EOFThe example uses heredoc to direct code to standard input of duct that is
going to be formatter with black with the max line length set to 79
characters. The output is going to be written to stdout accordingly. This
lets you use black in vim as if it was a regular filter command, which
makes life much easier for a regular Python dev.
In case the wrapped command writes the formatted code output to stdout or
stderr, duct has two flags -stdout and -stderr that attach them to the
wrapped command instead of redirecting the whole R/W flow through a temporary
file.
Consult Makefile to see how to format, examine code with go vet,
run unit test, run code linter with golint in order to get test coverage and
check if the package builds all right.
Remember to install golint before you try to run tests and test the build:
go install golang.org/x/lint/golint@latestCopyright (c) 2023 Michał Adamczyk.
This project is licensed under the MIT license. See LICENSE for more details.