gitee.com/mirrors_u-root/u-root@v7.0.0+incompatible/cmds/core/ts/ts.go (about)

     1  // Copyright 2020 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // ts prepends each line of stdin with a timestamp.
     6  //
     7  // Synopsis:
     8  //     ts
     9  package main
    10  
    11  import (
    12  	"io"
    13  	"log"
    14  	"os"
    15  
    16  	flag "github.com/spf13/pflag"
    17  	"github.com/u-root/u-root/pkg/ts"
    18  )
    19  
    20  var (
    21  	first    = flag.Bool("f", false, "All timestamps are relative to the first character")
    22  	relative = flag.Bool("R", false, "Timestamps are relative to the previous timestamp")
    23  )
    24  
    25  func main() {
    26  	flag.Parse()
    27  	if flag.NArg() != 0 {
    28  		log.Fatal("Usage: ts")
    29  	}
    30  
    31  	t := ts.New(os.Stdin)
    32  	t.ResetTimeOnNextRead = *first
    33  	if *relative {
    34  		t.Format = ts.NewRelativeFormat()
    35  	}
    36  
    37  	_, err := io.Copy(os.Stdout, t)
    38  	if err != nil {
    39  		log.Fatal(err)
    40  	}
    41  }