2019-01-08 18:52:14 +08:00
|
|
|
package vfsflags
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FileMode is a command line friendly os.FileMode
|
|
|
|
type FileMode struct {
|
|
|
|
Mode *os.FileMode
|
|
|
|
}
|
|
|
|
|
|
|
|
// String turns FileMode into a string
|
|
|
|
func (x *FileMode) String() string {
|
|
|
|
return fmt.Sprintf("0%3o", *x.Mode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a FileMode
|
|
|
|
func (x *FileMode) Set(s string) error {
|
|
|
|
i, err := strconv.ParseInt(s, 8, 64)
|
|
|
|
if err != nil {
|
2022-06-09 04:54:39 +08:00
|
|
|
return fmt.Errorf("bad FileMode - must be octal digits: %w", err)
|
2019-01-08 18:52:14 +08:00
|
|
|
}
|
|
|
|
*x.Mode = (os.FileMode)(i)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Type of the value
|
|
|
|
func (x *FileMode) Type() string {
|
2019-02-07 19:57:26 +08:00
|
|
|
return "FileMode"
|
2019-01-08 18:52:14 +08:00
|
|
|
}
|