#!/usr/bin/env python3 
import subprocess
from textfree86 import cli

cmd = cli.Command('logdetails','write the uptime, uname, etc to a given file')
@cmd.run('--uptime? --uname? output:outfile')
def cmd_run(uptime, uname, output):
    out = []
    if uptime:
        p= subprocess.run("uptime", stdout=subprocess.PIPE)
        output.write(p.stdout)
        out.append("uptime")
    if uname:
        p= subprocess.run("uname", stdout=subprocess.PIPE)
        output.write(p.stdout)
        out.append("uname")
    if out:
        return "Wrote {} to log".format(",".join(out))
    else:
        return "Wrote nothing to log, try --uname/--uptime"
    
cmd.main(__name__)
