Skip to content

add a command to set/query a task's description #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,25 @@ the ctftime urls will be used to aid in the generation of writeups with the `wri

---

### 🐋 <u>d</u>ocker
### 🌹 <u>de</u>scription

```
$ ret description [task-description]
```

set or query a task's description with ret

supply no arguments to see the current description

note that task metadata is stored in hidden directory `.ret` and therefore scoped to the cwd

task metadata is stored in the `.ret/task.json` file

🔗 https://github.com/rerrorctf/ret/blob/main/commands/description.go

---

### 🐋 <u>do</u>cker

```
$ ret docker [ip] [port]
Expand Down
63 changes: 63 additions & 0 deletions commands/description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package commands

import (
"fmt"
"ret/config"
"ret/theme"
"ret/util"
)

func init() {
Commands = append(Commands, Command{
Name: "description",
Emoji: "🌹", // a rose by any other name would smell as 1337
Func: Description,
Help: DescriptionHelp,
Arguments: []Argument{
{
Name: "task-description",
Optional: true,
List: false,
},
},
SeeAlso: nil})
}

func DescriptionHelp() string {
return "set or query a task's description with ret\n\n" +
"supply no arguments to see the current description\n\n" +
"note that task metadata is stored in hidden directory " + theme.ColorCyan + "`.ret`" + theme.ColorReset + " and therefore scoped to the cwd\n\n" +
"task metadata is stored in the " + theme.ColorCyan + "`" + config.TaskFileName + "`" + theme.ColorReset + " file\n"
}

func displayCurrentTaskDescription() {
description := util.GetCurrentTaskDescription()
if len(description) == 0 {
return
}

fmt.Printf("🌹 "+theme.ColorBlue+"%s"+theme.ColorReset+"\n", description)
}

func setCurrentTaskDescription(newDescription string) {
oldDescription := util.GetCurrentTaskDescription()

if len(oldDescription) > 0 {
fmt.Printf(theme.ColorGray+"🌹 changing description from: "+theme.ColorRed+"%s"+theme.ColorGray+" to: "+theme.ColorGreen+"%s"+theme.ColorReset+"\n", oldDescription, newDescription)
} else {
fmt.Printf(theme.ColorGray+"🌹 setting description to: "+theme.ColorGreen+"%s"+theme.ColorReset+"\n", newDescription)
}

util.SetCurrentTaskDescription(newDescription)
}

func Description(args []string) {
if len(args) == 0 {
displayCurrentTaskDescription()
return
}

util.EnsureSkeleton()

setCurrentTaskDescription(args[0])
}
5 changes: 3 additions & 2 deletions data/task.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package data

type Task struct {
Name string `json:"name"`
Category string `json:"category"`
Name string `json:"name"`
Category string `json:"category"`
Description string `json:"description"`
}
11 changes: 11 additions & 0 deletions util/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,14 @@ func SetCurrentTaskCategory(category string) {
task.Category = category
SetCurrentTask(&task)
}

func GetCurrentTaskDescription() string {
task := GetCurrentTask()
return task.Description
}

func SetCurrentTaskDescription(description string) {
task := GetCurrentTask()
task.Description = description
SetCurrentTask(&task)
}