head_tail

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Head = &cli.Command{
	Name:  "head",
	Usage: "Display the first lines of a file",
	Flags: []cli.Flag{
		&cli.IntFlag{Name: "lines", Aliases: []string{"n"}, Value: 10, Usage: "Number of lines"},
	},
	Action: func(ctx context.Context, cmd *cli.Command) error {
		n := cmd.Int("lines")
		files := cmd.Args().Slice()

		if len(files) == 0 {
			return printLines(os.Stdin, n, true)
		}

		for _, file := range files {
			f, err := os.Open(file)
			if err != nil {
				return fmt.Errorf("head: %s: %v", file, err)
			}
			if err := printLines(f, n, true); err != nil {
				f.Close()
				return err
			}
			f.Close()
		}
		return nil
	},
}
View Source
var Tail = &cli.Command{
	Name:  "tail",
	Usage: "Display the last lines of a file",
	Flags: []cli.Flag{
		&cli.IntFlag{Name: "lines", Aliases: []string{"n"}, Value: 10, Usage: "Number of lines"},
	},
	Action: func(ctx context.Context, cmd *cli.Command) error {
		n := cmd.Int("lines")
		files := cmd.Args().Slice()

		if len(files) == 0 {
			return printLines(os.Stdin, n, false)
		}

		for _, file := range files {
			f, err := os.Open(file)
			if err != nil {
				return fmt.Errorf("tail: %s: %v", file, err)
			}
			if err := printLines(f, n, false); err != nil {
				f.Close()
				return err
			}
			f.Close()
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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