linep

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 13 Imported by: 0

README

linep

❯ linep
linep -- process lines by one liner

Usage:
linep LANG MAP [FLAGS]
linep LANG INIT MAP [FLAGS]
linep LANG INIT MAP REDUCE [FLAGS]

LANG: go, py, python, pipenv, rs, rust.

Requirements:
- go
- python, pipenv, pyenv
- cargo

Examples:
> seq 3 | linep go 'fmt.Println(x+"0")'
10
20
30

> seq 10 | linep rust 'let n:i32=x.parse().unwrap();if n%2==0{println!("{}",n)}'
2
4
6
8
10

> seq 4 | linep pipenv 'acc=[]' 'acc.append(int(x));print(math.prod(acc))' 'print(sum(acc))' --import 'math'
1
2
6
24
10

# without pipenv
> seq 3 | linep pipenv 'print(x+"0")' --cmd python --init 'sleep 0'
10
20
30
# is almost equivalent to
> seq 3 | linep py 'print(x+"0")'

# display formatted script via preCmd
> linep pipenv 'acc=[]' 'acc.append(int(x));print(math.prod(acc))' 'print(sum(acc))' --import 'math' --preCmd 'black --quiet' --dry
import sys
import signal
import math

signal.signal(signal.SIGPIPE, signal.SIG_DFL)
acc = []
try:
    for x in sys.stdin:
        x = x.rstrip()
        acc.append(int(x))
        print(math.prod(acc))
except BrokenPipeError:
    pass
print(sum(acc))

Environment variables:
You can use the flag name with the hyphen removed and converted to uppercase as an environment variable.
If both the corresponding flag and the environment variable are specified at the same time, the flag takes precedence.

Flags:
      --cmd string       override command to execute script; separated by space
      --debug            enable debug logs
      --dry              do not run; display generated script
      --import string    additional libraries; separated by pipe
      --init string      override commands to modify script environment; separated by semicolon
      --keep             keep generated script directory
      --main string      override script filename
      --preCmd string    additional command to modify script; separated by space; stdout will be modified file content
      --quiet            quiet stderr logs
      --tmpl string      override script template or template filename
      --workDir string   working directory (default ".linep")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConfigMerger

func NewConfigMerger() *structconfig.Merger[Config]

func NewStructConfig

func NewStructConfig() *structconfig.StructConfig[Config]

Types

type Config

type Config struct {
	InitCmd    [][]string `json:"initCmd" name:"init" usage:"override commands to modify script environment; separated by semicolon"`
	PreExecCmd []string   `` /* 129-byte string literal not displayed */
	ExecCmd    []string   `json:"cmd" name:"cmd" usage:"override command to execute script; separated by space"`
	Imports    []string   `json:"import" name:"import" usage:"additional libraries; separated by pipe"`
	Template   string     `json:"tmpl" name:"tmpl" usage:"override script template or template filename"`
	Main       string     `json:"main" name:"main" usage:"override script filename"`
	Dry        bool       `json:"dry" name:"dry" usage:"do not run; display generated script"`
	Debug      bool       `json:"debug" name:"debug" usage:"enable debug logs"`
	Quiet      bool       `json:"quiet" name:"quiet" usage:"quiet stderr logs"`
	Keep       bool       `json:"keep" name:"keep" usage:"keep generated script directory"`
	Lang       string     `json:"lang"`
	Init       string     `json:"init"`
	Map        string     `json:"map"`
	Reduce     string     `json:"reduce"`
	WorkDir    string     `json:"workDir" name:"workDir" usage:"working directory" default:".linep"`
}

func NewConfig

func NewConfig(fs *pflag.FlagSet) (*Config, error)

func (Config) SetupLogger

func (c Config) SetupLogger()

type Runner

type Runner Config

func (Runner) Run

func (r Runner) Run(ctx context.Context) error

Directories

Path Synopsis
cmd
linep command

Jump to

Keyboard shortcuts

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