github.com/primecitizens/pcz/std@v0.2.1/core/sys/argv.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  
     4  //go:build !noos
     5  
     6  package sys
     7  
     8  import (
     9  	"github.com/primecitizens/pcz/std/core/iter"
    10  )
    11  
    12  func (it ArgIter) Nth(i int) (arg string, ok bool) {
    13  	if it < 0 {
    14  		return
    15  	}
    16  
    17  	i, ok = iter.Index(i, len(args)-int(it))
    18  	if ok {
    19  		return ntharg(i), true
    20  	}
    21  
    22  	return
    23  }
    24  
    25  func (it ArgIter) Len() int { return len(args) - int(it) }
    26  
    27  func (it ArgIter) SliceFrom(start int) ArgIter {
    28  	start, ok := iter.Bound(start, len(args)-int(it))
    29  	if ok {
    30  		return it + ArgIter(start)
    31  	}
    32  
    33  	return ArgIter(len(args))
    34  }