Beispiel #1
0
func main() {
	var shouldInit bool

	flag.Usage = usage
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.Parse()

	if flag.NArg() == 0 {
		die.With("Workspace name is required.")
	}

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	var c *workspace.FilterChain
	if flag.NArg() == 1 {
		c, err = workspace.ProcessQuery([]string{}, workspace.StatusUncompleted)
	} else {
		c, err = workspace.ProcessQuery(flag.Args()[1:], workspace.StatusUncompleted)
	}
	die.If(err)

	entryID := ws.NewEntry()
	tasks := c.Filter(ws.EntryTasks(entryID)).Sort()
	fmt.Printf("TODO %s (%d tasks):\n",
		workspace.Today().Format(workspace.DateFormat),
		len(tasks))
	for i, task := range tasks {
		fmt.Println(i, task)
	}

	for {
		fmt.Printf("Task: ")
		line := readline()
		if line == "" {
			break
		}

		idx, err := strconv.Atoi(line)
		die.If(err)

		if idx > len(tasks) || idx < 0 {
			continue
		}

		task := tasks[idx]

		fmt.Printf("Backdating '%s'\n", task.Title)
		fmt.Printf("Date (YYYY-MM-DD): ")
		line = readline()
		date, err := time.Parse(workspace.DateFormat, line)
		die.If(err)
		task.Created = date

		ws.Tasks[task.ID] = task
		err = workspace.WriteFile(ws)
		die.If(err)
		break
	}
}
Beispiel #2
0
func main() {
	var shouldInit bool
	var flagTags string
	var priority = workspace.PriorityNormal.String()

	flag.Usage = usage
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.StringVar(&priority, "p", priority, "Specify the priority for new tasks.")
	flag.StringVar(&flagTags, "t", "", "Specify tags to be applied to new tasks.")
	flag.Parse()

	if flag.NArg() == 0 {
		usage()
		return
	}

	pri := workspace.PriorityFromString(priority)
	if pri == workspace.PriorityUnknown {
		usage()
		os.Exit(1)
	}

	tags := workspace.Tokenize(flagTags, ",")

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	entryID := ws.NewEntry()
	entry := ws.Entries[entryID]

	for {
		tasks := ws.EntryTasks(entryID).Sort()
		fmt.Printf("TODO %s (%d tasks):\n",
			workspace.Today().Format(workspace.DateFormat),
			len(tasks))
		for _, task := range tasks {
			fmt.Println(task)
		}

		fmt.Printf("New task: ")
		line := readline()
		if line == "" {
			break
		}

		id := workspace.NewTaskID()
		task := workspace.NewTask(id, line)
		task.Priority = pri
		entry.Tasks = append(entry.Tasks, id)
		ws.Tasks[id] = task
		ws.Entries[entryID] = entry

		for i := range tags {
			ws.Tag(task.ID, tags[i])
		}

		err = workspace.WriteFile(ws)
		die.If(err)
	}
}
Beispiel #3
0
func main() {
	var shouldInit bool
	var fromFile string

	flag.Usage = usage
	flag.StringVar(&fromFile, "f", "", "Read annotations from a file.")
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.Parse()

	if flag.NArg() == 0 {
		die.With("Workspace name is required.")
	}

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	entryID := ws.NewEntry()
	tasks := ws.EntryTasks(entryID).Unfinished().Sort()

	for {
		fmt.Println("Today's TODO:")
		for i, task := range tasks {
			fmt.Println(i, task)
			if len(task.Tags) == 0 {
				continue
			}
			fmt.Println("\tTags:", task.TagString())
		}

		fmt.Printf("Task: ")
		line := readline()
		if line == "" {
			break
		}

		idx, err := strconv.Atoi(line)
		die.If(err)

		if idx > len(tasks) || idx < 0 {
			continue
		}

		task := tasks[idx]
		fmt.Println("Current tags:", task.TagString())
		fmt.Printf("Tags to be added: ")
		line = readline()
		tags := workspace.Tokenize(line, ",")
		for i := range tags {
			ws.Tag(task.ID, tags[i])
		}

		err = workspace.WriteFile(ws)
		die.If(err)

	}
}
Beispiel #4
0
func main() {
	var shouldInit bool

	flag.Usage = usage
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.Parse()

	if flag.NArg() == 0 {
		die.With("Workspace name is required.")
	}

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	entryID := ws.NewEntry()
	for {
		var c *workspace.FilterChain
		if flag.NArg() == 1 {
			c, err = workspace.ProcessQuery([]string{}, workspace.StatusUncompleted)
		} else {
			c, err = workspace.ProcessQuery(flag.Args()[1:], workspace.StatusUncompleted)
		}
		die.If(err)

		tasks := c.Filter(ws.EntryTasks(entryID)).Sort()
		fmt.Println("Today's TODO:")
		for i, task := range tasks {
			fmt.Println(i, task)
		}

		fmt.Printf("Task: ")
		line := readline()
		if line == "" {
			break
		}

		idx, err := strconv.Atoi(line)
		die.If(err)

		if idx > len(tasks) || idx < 0 {
			continue
		}

		task := tasks[idx]
		pri := readPriority()
		task.Priority = pri
		ws.Tasks[task.ID] = task
		err = workspace.WriteFile(ws)
		die.If(err)
	}
}
Beispiel #5
0
func main() {
	var cfg = &tls.Config{}

	var sysRoot, serverName string
	flag.StringVar(&sysRoot, "ca", "", "provide an alternate CA bundle")
	flag.StringVar(&cfg.ServerName, "sni", cfg.ServerName, "provide an SNI name")
	flag.BoolVar(&cfg.InsecureSkipVerify, "noverify", false, "don't verify certificates")
	flag.Parse()

	if sysRoot != "" {
		pemList, err := ioutil.ReadFile(sysRoot)
		die.If(err)

		roots := x509.NewCertPool()
		if !roots.AppendCertsFromPEM(pemList) {
			fmt.Printf("[!] no valid roots found")
			roots = nil
		}

		cfg.RootCAs = roots
	}

	if serverName != "" {
		cfg.ServerName = serverName
	}

	for _, site := range flag.Args() {
		conn, err := tls.Dial("tcp", site+":443", cfg)
		if err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}

		cs := conn.ConnectionState()
		var chain []byte

		for _, cert := range cs.PeerCertificates {
			p := &pem.Block{
				Type:  "CERTIFICATE",
				Bytes: cert.Raw,
			}
			chain = append(chain, pem.EncodeToMemory(p)...)
		}

		err = ioutil.WriteFile(site+".pem", chain, 0644)
		die.If(err)
		fmt.Printf("[+] wrote %s.pem.\n", site)
	}
}
Beispiel #6
0
func main() {
	flag.Parse()

	for _, server := range flag.Args() {
		if !hasPort.MatchString(server) {
			server += ":443"
		}

		var chain string

		conn, err := tls.Dial("tcp", server, nil)
		die.If(err)

		details := conn.ConnectionState()
		for _, cert := range details.PeerCertificates {
			p := pem.Block{
				Type:  "CERTIFICATE",
				Bytes: cert.Raw,
			}
			chain += string(pem.EncodeToMemory(&p))
		}

		fmt.Println(chain)
	}
}
Beispiel #7
0
func main() {
	var shouldInit, long, markdown bool

	flag.Usage = usage
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.BoolVar(&long, "l", false, "Show annotations of each task.")
	flag.BoolVar(&markdown, "m", false, "Print log as markdown.")
	flag.Parse()

	if flag.NArg() == 0 {
		die.With("Workspace name is required.")
	}

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	var c *workspace.FilterChain
	if flag.NArg() == 1 {
		c, err = workspace.ProcessQuery([]string{}, workspace.StatusUncompleted)
	} else {
		c, err = workspace.ProcessQuery(flag.Args()[1:], workspace.StatusUncompleted)
	}
	die.If(err)

	entryID := ws.NewEntry()
	tasks := c.Filter(ws.EntryTasks(entryID)).Sort()
	if markdown {
		asMarkdown(tasks, long)
	} else {
		fmt.Printf("TODO %s (%d tasks):\n",
			workspace.Today().Format(workspace.DateFormat),
			len(tasks))
		for _, task := range tasks {
			fmt.Println("\t", task)
			if long {
				if len(task.Tags) > 0 {
					fmt.Printf("\t\tTags: %s\n", task.TagString())
				}

				for _, note := range task.Notes {
					fmt.Println(workspace.Wrap("+ "+note, "\t\t", 72))
				}
			}
		}
	}
}
Beispiel #8
0
func main() {
	verbose := flag.Bool("v", false, "log debugging information")
	flag.Parse()

	if *verbose {
		log.SetLevel(logging.LevelDebug)
	}
	err := filepath.Walk(".", walkFile)
	die.If(err)

	fmt.Println("External imports:")
	importList := make([]string, 0, len(imports))
	for imp := range imports {
		importList = append(importList, imp)
	}
	sort.Strings(importList)

	for _, imp := range importList {
		fmt.Println("\t", imp)
	}
}
Beispiel #9
0
func readline() string {
	line, err := stdin.ReadString('\n')
	die.If(err)

	return strings.TrimSpace(line)
}
Beispiel #10
0
func main() {
	var shouldInit bool
	var fromFile string

	flag.Usage = usage
	flag.StringVar(&fromFile, "f", "", "Read annotations from a file.")
	flag.BoolVar(&shouldInit, "i", false, "Initialise new workspace if needed.")
	flag.Parse()

	if flag.NArg() == 0 {
		die.With("Workspace name is required.")
	}

	ws, err := workspace.ReadFile(flag.Arg(0), shouldInit)
	die.If(err)

	var c *workspace.FilterChain
	if flag.NArg() == 1 {
		c, err = workspace.ProcessQuery([]string{}, workspace.StatusUncompleted)
	} else {
		c, err = workspace.ProcessQuery(flag.Args()[1:], workspace.StatusUncompleted)
	}
	die.If(err)

	entryID := ws.NewEntry()
	tasks := c.Filter(ws.EntryTasks(entryID)).Sort()
	fmt.Println("Today's TODO:")
	for i, task := range tasks {
		fmt.Println(i, task)
	}

	for {
		fmt.Printf("Task: ")
		line := readline()
		if line == "" {
			break
		}

		idx, err := strconv.Atoi(line)
		die.If(err)

		if idx > len(tasks) || idx < 0 {
			continue
		}

		task := tasks[idx]

		var annotations []string
		if fromFile == "" {
			fmt.Println(`Enter annotations; each annotation should be separated by a newlines. Finish
the annotation with a pair of newlines.`)
			annotations = readAnnotationsStdin()

		} else {
			file, err := os.Open(fromFile)
			die.If(err)
			defer file.Close()
			annotations = readAnnotationsFile(file)
		}

		if len(annotations) > 0 {
			task.Notes = annotations
		}

		ws.Tasks[task.ID] = task
		err = workspace.WriteFile(ws)
		die.If(err)
		break

	}
}