workingdir

package module
v0.0.0-...-f48f491 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 4 Imported by: 0

README

workingdir

Package for running quick commands and simple interaction with directories.

Quick example
package main

import (
	wd "github.com/xyproto/workingdir"
)

func main() {
	print(wd.Run("echo hello"))
}
Another example
package main

import (
	"fmt"
	wd "github.com/xyproto/workingdir"
)

func main() {
	dir, err := wd.New("/tmp")
	if err != nil {
		panic(err)
	}
	fmt.Printf("There are %d entries in %s\n", len(dir.List()), dir.Path())
	fmt.Printf("Current date: %s\n", dir.TrimRun("date --iso-8601"))
}
General info

Documentation

Overview

Example
dir, err := New(".")
if err != nil {
	panic("error!")
}

for _, f := range dir.List() {
	if f == "workingdir_test.go" {
		fmt.Println(f)
	}
}

dir.Run("mkdir -p test")
dir2, err := New("test")

dir2.Run("touch fil")

fmt.Print(dir2.Run("ls fil"))

dir2.Run("rm fil")
dir.Run("rmdir test")

for _, f := range dir.List() {
	if f == "workingdir_test.go" {
		fmt.Println(f)
	}
}

fmt.Println(dir.Run("find . -name workingdir_test.go -type f"))
Output:

workingdir_test.go
fil
workingdir_test.go
./workingdir_test.go

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cmd string) string

Execute a command in the current directory. Return the combined output or an empty string.

func TrimRun

func TrimRun(cmd string) string

Execute a command in the current directory. Return the combined output, trimmed, or an empty string.

Types

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

func New

func New(path string) (*Dir, error)

Create a new "working directory" struct

func (*Dir) List

func (d *Dir) List() []string

List the contents of the directory

func (*Dir) Path

func (d *Dir) Path() string

Path returns the path of the directory

func (*Dir) Run

func (d *Dir) Run(cmd string) string

Execute a command in the current directory. Return the combined output, or an empty string.

func (*Dir) TrimRun

func (d *Dir) TrimRun(cmd string) string

Execute a command in the current directory. Return the combined output, trimmed, or an empty string.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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