Changed name from Venture to CheckIn.
parent
23a4e07c1d
commit
2438bc43c0
|
@ -1 +1 @@
|
||||||
Venture
|
CheckIn
|
10
README.md
10
README.md
|
@ -1,7 +1,13 @@
|
||||||
# Venture
|
# CheckIn
|
||||||
|
|
||||||
A way to let other people know what the heck you're up to.
|
A way to let other people know what the heck you're up to.
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
|
|
||||||
`venture "<username>[message]"`
|
`checkin set [--include-wd]`
|
||||||
|
|
||||||
|
`--include-wd` will include your current working directory in your message.
|
||||||
|
|
||||||
|
`checkin get [--freshness=14]`
|
||||||
|
|
||||||
|
`--freshness` controls how new (in days) messages must be in order to be printed.
|
54
main.go
54
main.go
|
@ -18,12 +18,12 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
switch flag.Arg(0) {
|
switch flag.Arg(0) {
|
||||||
case "set":
|
case "set":
|
||||||
err := SetVenture(flag.Args()[1:])
|
err := SetStatus(flag.Args()[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Could not set: %v", err)
|
fmt.Fprintf(os.Stderr, "Could not set: %v", err)
|
||||||
}
|
}
|
||||||
case "get":
|
case "get":
|
||||||
err := GetVenture(flag.Args()[1:])
|
err := GetStatus(flag.Args()[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Could not get: %v", err)
|
fmt.Fprintf(os.Stderr, "Could not get: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -33,63 +33,63 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVenture collects all recent ventures from all users on the system.
|
// GetStatus collects all recent statuses from all users on the system.
|
||||||
// Any errors that occur while pulling individual ventures are silently ignored
|
// Any errors that occur while pulling individual statuss are silently ignored
|
||||||
func GetVenture(args []string) error {
|
func GetStatus(args []string) error {
|
||||||
getFlags := flag.NewFlagSet(os.Args[0]+" get", flag.ExitOnError)
|
getFlags := flag.NewFlagSet(os.Args[0]+" get", flag.ExitOnError)
|
||||||
freshDays := getFlags.Int("freshness", 14, "get all ventures newer than this number of days")
|
freshDays := getFlags.Int("freshness", 14, "get all statuses newer than this number of days")
|
||||||
getFlags.Parse(args)
|
getFlags.Parse(args)
|
||||||
|
|
||||||
freshLimit := time.Now().AddDate(0, 0, *freshDays*-1)
|
freshLimit := time.Now().AddDate(0, 0, *freshDays*-1)
|
||||||
|
|
||||||
allVenturePaths, err := filepath.Glob("/home/*/.venture")
|
allStatusPaths, err := filepath.Glob("/home/*/.checkin")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// *Should* never happen, since path is hardcoded and that's the only reason Glob can error out.
|
// *Should* never happen, since path is hardcoded and that's the only reason Glob can error out.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out any ventures that are older than our cutoff time.
|
// Filter out any statuses that are older than our cutoff time.
|
||||||
freshVenturePaths := make([]string, 0, len(allVenturePaths))
|
freshStatusPaths := make([]string, 0, len(allStatusPaths))
|
||||||
for _, venturePath := range allVenturePaths {
|
for _, statusPath := range allStatusPaths {
|
||||||
ventureInfo, err := os.Stat(venturePath)
|
statusInfo, err := os.Stat(statusPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ventureInfo.ModTime().After(freshLimit) {
|
if statusInfo.ModTime().After(freshLimit) {
|
||||||
freshVenturePaths = append(freshVenturePaths, venturePath)
|
freshStatusPaths = append(freshStatusPaths, statusPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the contents of all ventures
|
// Print the contents of all statuses
|
||||||
for _, venturePath := range freshVenturePaths {
|
for _, statusPath := range freshStatusPaths {
|
||||||
ventureBytes, err := ioutil.ReadFile(venturePath)
|
statusBytes, err := ioutil.ReadFile(statusPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
venture := string(ventureBytes)
|
status := string(statusBytes)
|
||||||
|
|
||||||
// Check to see if file starts with user's name.
|
// Check to see if file starts with user's name.
|
||||||
if !strings.HasPrefix(venture, "~") {
|
if !strings.HasPrefix(status, "~") {
|
||||||
// Strip /home from path
|
// Strip /home from path
|
||||||
homelessPath, err := filepath.Rel("/home", venturePath)
|
homelessPath, err := filepath.Rel("/home", statusPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Strip .venture from path, leaving us with the user's name.
|
// Strip .checkin from path, leaving us with the user's name.
|
||||||
username := filepath.Dir(homelessPath)
|
username := filepath.Dir(homelessPath)
|
||||||
venture = fmt.Sprintf("~%s: %s", username, venture)
|
status = fmt.Sprintf("~%s: %s", username, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trim trailing newline (if any)
|
// Trim trailing newline (if any)
|
||||||
venture = strings.TrimSpace(venture)
|
status = strings.TrimSpace(status)
|
||||||
|
|
||||||
fmt.Println(venture)
|
fmt.Println(status)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetVenture sets the curent user's venture, either by reading the value from the command line or by prompting the user to input it interactively.
|
// SetStatus sets the curent user's status, either by reading the value from the command line or by prompting the user to input it interactively.
|
||||||
func SetVenture(args []string) error {
|
func SetStatus(args []string) error {
|
||||||
setFlags := flag.NewFlagSet(os.Args[0]+" set", flag.ExitOnError)
|
setFlags := flag.NewFlagSet(os.Args[0]+" set", flag.ExitOnError)
|
||||||
includeWd := setFlags.Bool("include-wd", false, "if set, appends working directory to your message")
|
includeWd := setFlags.Bool("include-wd", false, "if set, appends working directory to your message")
|
||||||
setFlags.Parse(args)
|
setFlags.Parse(args)
|
||||||
|
@ -99,8 +99,8 @@ func SetVenture(args []string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// User status is written to ~/.venture
|
// User status is written to ~/.checkin
|
||||||
outputPath := path.Join(curUser.HomeDir, ".venture")
|
outputPath := path.Join(curUser.HomeDir, ".checkin")
|
||||||
|
|
||||||
// Prompt user for input
|
// Prompt user for input
|
||||||
fmt.Printf("What's ~%v been up to?\n~%v", curUser.Username, curUser.Username)
|
fmt.Printf("What's ~%v been up to?\n~%v", curUser.Username, curUser.Username)
|
||||||
|
|
Loading…
Reference in New Issue