jim

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: MIT Imports: 7 Imported by: 2

README

Jim

Jim is a task runner, similiar to https://github.com/markbates/grift.

Requirements
  • Go 1.13+
  • Modules

Installation

$ go get github.com/markbates/jim/cmd/jim

Usage

To create a new task that you can run with jim. You need to create a package level function with the following API in your module:

func <name>(ctx context.Context, args []string) error {
	return nil
}

You can place these functions anywhere in your application in any package. You don't need to follow any naming conventions or use any special build tags. Your function need only take a context#Context and a slice of string, and return an error.

See the ./examples/ref application for the full code.

.
├── db
│   ├── seed
│   │   └── users.go
│   └── seed.go
├── go.mod
├── go.sum
├── ref.go
└── task
    └── task.go

3 directories, 6 files

The go.mod file:

module ref

go 1.13

Example task ref/db/seed/users.go

package seed

import (
	"context"
	"fmt"
)

// Users puts all of the users into all of the databases
func Users(ctx context.Context, args []string) error {
	fmt.Println("loading users", args)
	return nil
}
Running a Task via CLI

To run the above mentioned task we can use the jim command:

$ jim db:seed:Users 1 2 3 4

loading users [1 2 3 4]

Let's break down the db:seed:Users bit, shall we? The last part, Users is the name of the function that will be run. This MUST match capitalization.

The db:seed part is converted to the package <module path>/db/seed which, hopefully, contains a Users function that matches the correct API.

Running a Task via API

To run your task programmatically in your application, give it a context.Context and you're good to go. :)

Getting Task Help

The jim -h flag, followed by the task will print the GoDoc for that function.

$ jim -h db:seed:Users

package seed // import "ref/db/seed"

func Users(ctx context.Context, args []string) error
    Users puts all of the users into all of the databases

Documentation

Index

Constants

View Source
const Version = "v0.1.0"

Version of jim

Variables

This section is empty.

Functions

func Err

func Err(ctx context.Context) io.Writer

func In

func In(ctx context.Context) io.Reader

func Out

func Out(ctx context.Context) io.Writer

Types

type Context

type Context struct {
	context.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx context.Context) Context

func (Context) Stderr

func (c Context) Stderr() io.Writer

func (Context) Stdin

func (c Context) Stdin() io.Reader

func (Context) Stdout

func (c Context) Stdout() io.Writer

type Erry

type Erry interface {
	Stderr() io.Writer
}

type Iny

type Iny interface {
	Stdin() io.Reader
}

type Outy

type Outy interface {
	Stdout() io.Writer
}

type Task

type Task struct {
	here.Info
	Args []string
	Pkg  string // github.com/foo/bar
	Sel  string // bar
	Name string // Something
}

func New

func New(args []string) (*Task, error)

Directories

Path Synopsis
cmd
jim

Jump to

Keyboard shortcuts

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