Skip to content

Commit

Permalink
feat: list all services implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DeeStarks committed Aug 9, 2022
1 parent 0f922e4 commit a894563
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion app/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,59 @@ func (ac *AppCommand) ListRunning() {

// List all applications
func (ac *AppCommand) ListAll() {
log.Println("All processes")
rows, err := ac.defaultDB.Query(`
SELECT
pid, name, status, type, listeners,
root_directory, client_address, tunnelled, created_at
FROM processes
`)
if err != nil {
log.Println("Error retrieving running apps:", err)
return
}

// Parse result
var processes []AppProcess
for rows.Next() {
var process AppProcess
var listeners string

err = rows.Scan(
&process.Pid, &process.Name, &process.Status, &process.Type,
&listeners, &process.RootDirectory, &process.ClientAddress,
&process.Tunnelled, &process.CreatedAt,
)
if err != nil {
log.Println("Error retrieving running apps:", err)
return
}

// Listeners are stored in the db a string separated by comma
// we'll split that into slice
process.Listeners = strings.Split(listeners, ",")
// Append the process to list of processes
processes = append(processes, process)
}

// Draw table to list processes
t := table.New(os.Stdout)
t.SetDividers(table.UnicodeRoundedDividers)

t.SetHeaders("PID", "NAME", "STATUS", "TYPE", "LISTENERS", "ROOT", "CLIENT", "TUNNELLED", "CREATED")
for _, p := range processes {
created_at := utils.TimeAgo(p.CreatedAt, time.Now().Unix())
listeners := strings.Join(p.Listeners, ", ")
tunnelled := "False"
if p.Tunnelled {
tunnelled = "True"
}

t.AddRow(
string(p.Pid), p.Name, p.Status, p.Type, listeners, p.RootDirectory,
p.ClientAddress, tunnelled, created_at,
)
}
t.Render()
}

// Add new application
Expand Down

0 comments on commit a894563

Please sign in to comment.