coming allong nicely. adding more commands, tests, and
artifacts for testing. basic framework down just adding features now
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# functions for commands needed
|
||||
# src/commands.py
|
||||
|
||||
# vim foldmethod=marker
|
||||
import click
|
||||
from pathlib import Path
|
||||
|
||||
@@ -48,11 +50,16 @@ def set_flag_format(pattern: str, original: str):
|
||||
if "Competition" not in config:
|
||||
config["Competition"] = {}
|
||||
|
||||
comp_name = config["Competition"].get("competition", "")
|
||||
|
||||
if original:
|
||||
if not original.strip():
|
||||
raise click.UsageError("Original flag cannot be empty or whitespace only.")
|
||||
patterns = suggest_patterns(original)
|
||||
click.echo("Suggested regex patterns:")
|
||||
if comp_name and comp_name.lower() not in original.lower():
|
||||
click.echo(f"Warning: Current competition name '{comp_name}' was not found in the example flag.")
|
||||
|
||||
patterns = suggest_patterns(original, comp_name=comp_name)
|
||||
click.echo(f"Suggested regex patterns for competition {comp_name}:")
|
||||
for i, pat in enumerate(patterns, 1):
|
||||
click.echo(f" {i}. {pat}")
|
||||
|
||||
@@ -64,15 +71,22 @@ def set_flag_format(pattern: str, original: str):
|
||||
click.echo(f"Flag format set to: {pattern}")
|
||||
# }}}
|
||||
|
||||
# def Set_Challenge(comp: str, chal: str, setDirectory: bool):
|
||||
# # set the current challenge and competition from input
|
||||
# if state.current_comp != comp:
|
||||
# state.current_comp=comp
|
||||
# state.comp_dir=pathlib
|
||||
# # TODO archive the old competitions
|
||||
#
|
||||
# if state.current_chal != chal:
|
||||
# state.current_chal=chal
|
||||
# print("challenge already set")
|
||||
# # TODO archive the old challenges
|
||||
# # TODO set the directory to challenge directory, with ignore option
|
||||
# {{{ set_competition
|
||||
# Sets the competition name in config.toml
|
||||
@basic_group.command(name="set-competition")
|
||||
@click.argument("name")
|
||||
def set_competition(name: str):
|
||||
"""Set the name of the active competition."""
|
||||
from ctf.utils import load_config, write_config
|
||||
|
||||
config_path = "/home/venus/code/ctf/config.toml"
|
||||
config = load_config(config_path)
|
||||
|
||||
if "Competition" not in config:
|
||||
config["Competition"] = {}
|
||||
|
||||
config["Competition"]["competition"] = name
|
||||
write_config(config, config_path)
|
||||
click.echo(f"Competition name set to: {name}")
|
||||
# }}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user