github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/core/ls/ls_plan9.go (about)

     1  // Copyright 2021 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  //go:build plan9
     6  // +build plan9
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"io"
    13  	"strings"
    14  
    15  	flag "github.com/spf13/pflag"
    16  	"github.com/mvdan/u-root-coreutils/pkg/ls"
    17  )
    18  
    19  var final = flag.BoolP("print-last", "p", false, "Print only the final path element of each file name")
    20  
    21  func printFile(w io.Writer, stringer ls.Stringer, f file) {
    22  	if f.err != nil {
    23  		fmt.Fprintln(w, f.err)
    24  		return
    25  	}
    26  	// Hide .files unless -a was given
    27  	if *all || !strings.HasPrefix(f.lsfi.Name, ".") {
    28  		// Unless they said -p, we always print the full path
    29  		if !*final {
    30  			f.lsfi.Name = f.path
    31  		}
    32  		if *classify {
    33  			f.lsfi.Name = f.lsfi.Name + indicator(f.lsfi)
    34  		}
    35  		fmt.Fprintln(w, stringer.FileString(f.lsfi))
    36  	}
    37  }