<commit_before>/**
 * @file tfhctl.go
 * @author <NAME> jollheef<AT>riseup.net
 * @license GNU GPLv3
 * @date September, 2015
 * @brief contest checking system CLI
 *
 * Entry point for contest checking system CLI
 */

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"gopkg.in/alecthomas/kingpin.v2"
	"log"
	"os"
)

import (
	"tinfoilhat/config"
	"tinfoilhat/scoreboard"
	"tinfoilhat/steward"
)

var (
	config_path = kingpin.Flag("config",
		"Path to configuration file.").Required().String()

	score = kingpin.Command("scoreboard", "View scoreboard.")

	adv = kingpin.Command("advisory", "Work with advisories.")

	advList = adv.Command("list", "List advisories.")

	advReview   = adv.Command("review", "Review advisory.")
	advReviewId = advReview.Arg("id", "advisory id").Required().Int()
	advScore    = advReview.Arg("score", "advisory id").Required().Int()

	advHide   = adv.Command("hide", "Hide advisory.")
	advHideId = advHide.Arg("id", "advisory id").Required().Int()

	advUnhide   = adv.Command("unhide", "Unhide advisory.")
	advUnhideId = advUnhide.Arg("id", "advisory id").Required().Int()
)

var (
	COMMIT_ID  string
	BUILD_DATE string
	BUILD_TIME string
)

func buildInfo() (str string) {
	str = fmt.Sprintf("Version: tin_foil_hat %s %s %s\n",
		COMMIT_ID[:7], BUILD_DATE, BUILD_TIME)
	str += "Author: <NAME> <<EMAIL>>\n"
	return
}

func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	config, err := config.ReadConfig(*config_path)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	switch kingpin.Parse() {
	case "advisory list":
		advisories, err := steward.GetAdvisories(db)
		if err != nil {
			log.Fatalln("Get advisories fail:", err)
		}

		for _, advisory := range advisories {

			fmt.Printf(">>> Advisory: id %d <<<\n", advisory.Id)
			fmt.Printf("(Score: %d, Reviewed: %t, Timestamp: %s)\n",
				advisory.Score, advisory.Reviewed,
				advisory.Timestamp.String())

			fmt.Println(advisory.Text)
		}

	case "advisory review":
		err := steward.ReviewAdvisory(db, *advReviewId, *advScore)
		if err != nil {
			log.Fatalln("Advisory review fail:", err)
		}

	case "advisory hide":
		err := steward.HideAdvisory(db, *advHideId, true)
		if err != nil {
			log.Fatalln("Advisory hide fail:", err)
		}

	case "advisory unhide":<commit_msg>Now CLI can list only not reviewed advisory<commit_after>/**
 * @file tfhctl.go
 * @author <NAME> <EMAIL><AT><EMAIL>
 * @license GNU GPLv3
 * @date September, 2015
 * @brief contest checking system CLI
 *
 * Entry point for contest checking system CLI
 */

package main

import (
	"fmt"
	"github.com/olekukonko/tablewriter"
	"gopkg.in/alecthomas/kingpin.v2"
	"log"
	"os"
)

import (
	"tinfoilhat/config"
	"tinfoilhat/scoreboard"
	"tinfoilhat/steward"
)

var (
	config_path = kingpin.Flag("config",
		"Path to configuration file.").Required().String()

	score = kingpin.Command("scoreboard", "View scoreboard.")

	adv = kingpin.Command("advisory", "Work with advisories.")

	advList        = adv.Command("list", "List advisories.")
	advNotReviewed = adv.Flag("not-reviewed", "List only not reviewed advisory.").Bool()

	advReview   = adv.Command("review", "Review advisory.")
	advReviewId = advReview.Arg("id", "advisory id").Required().Int()
	advScore    = advReview.Arg("score", "advisory id").Required().Int()

	advHide   = adv.Command("hide", "Hide advisory.")
	advHideId = advHide.Arg("id", "advisory id").Required().Int()

	advUnhide   = adv.Command("unhide", "Unhide advisory.")
	advUnhideId = advUnhide.Arg("id", "advisory id").Required().Int()
)

var (
	COMMIT_ID  string
	BUILD_DATE string
	BUILD_TIME string
)

func buildInfo() (str string) {
	str = fmt.Sprintf("Version: tin_foil_hat %s %s %s\n",
		COMMIT_ID[:7], BUILD_DATE, BUILD_TIME)
	str += "Author: <NAME> <<EMAIL>>\n"
	return
}

func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	config, err := config.ReadConfig(*config_path)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	switch kingpin.Parse() {
	case "advisory list":
		advisories, err := steward.GetAdvisories(db)
		if err != nil {
			log.Fatalln("Get advisories fail:", err)
		}

		for _, advisory := range advisories {

			if *advNotReviewed && advisory.Reviewed {
				continue
			}

			fmt.Printf(">>> Advisory: id %d <<<\n", advisory.Id)
			fmt.Printf("(Score: %d, Reviewed: %t, Timestamp: %s)\n",
				advisory.Score, advisory.Reviewed,
				advisory.Timestamp.String())

			fmt.Println(advisory.Text)
		}

	case "advisory review":
		err := steward.ReviewAdvisory(db, *advReviewId, *advScore)
		if err != nil {
			log.Fatalln("Advisory review fail:", err)
		}

	case "advisory hide":
		err := steward.HideAdvisory(db, *advHideId, true)
		if err != nil {
			log.Fatalln("Advisory hide fail:", err)
		}

	case "advisory unhide":
{'fraction_non_alphanumeric': 0.1631507644668086, 'fraction_numerical': 0.0027095026127346624, 'mean_word_length': 4.209677419354839, 'pattern_counts': {'":': 8, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6926448', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1840, 'n_words': 421}