Skip to content

CLI tools


minall.cli.run

CLI action for minall workflow.

This module contains the function cli(), which runs the minall workflow as a CLI tool.

The function cli() requests and parses the command-line arguments that are necessary to create an instance of the Minall class. Then, it deploys the Minall class's workflow.

cli()

Run minall workflow from the command line.

Source code in minall/cli/run.py
14
15
16
17
18
19
20
21
22
23
def cli():
    """Run minall workflow from the command line."""

    args = cli_args()

    app = Minall(**args)

    app.collect_and_coalesce()

    app.export()

minall.cli.parse_args

Helper functions for CLI action.

This module contains the following helper functions for parsing command-line arguments:

  • cli_args() - Parse CLI arguments.
  • dir_path(path_name) - Create directory and necessary parent directories.
  • file_path(path_name) - Verify existence of given file.
  • has_parent(path_name) - Create necessary parent directories for file path.

cli_args()

Function to call and parse command-line arguments.

Returns:

Name Type Description
dict dict

Dictionary of parsed command-line arguments.

Source code in minall/cli/parse_args.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def cli_args() -> dict:
    """Function to call and parse command-line arguments.

    Returns:
        dict: Dictionary of parsed command-line arguments.
    """
    parser = ArgumentParser(
        add_help=True, prog="Minall", formatter_class=RawDescriptionHelpFormatter
    )
    parser.add_argument(
        "--database",
        dest="database",
        required=False,
        type=has_parent,
        help="[Optional] Path to SQLite database. If not given, database written to memory.",
    )
    parser.add_argument(
        "--config",
        dest="config",
        type=file_path,
        required=False,
        help="[Optional] Path to configuration file. If not given, environment variables are expected.",
    )
    parser.add_argument(
        "--output-dir",
        dest="output_dir",
        type=dir_path,
        required=True,
        help="[Required] Path to directory in which a links and shared_content file will be written.",
    )
    parser.add_argument(
        "--links",
        dest="links_file",
        type=file_path,
        required=True,
        help="[Required] Path to links file.",
    )
    parser.add_argument(
        "--url-col",
        dest="url_col",
        type=str,
        required=True,
        help="[Required] Name of URL column in links file.",
    )
    parser.add_argument(
        "--shared-content",
        dest="shared_content_file",
        type=file_path,
        required=False,
        help="[Optional] Path to shared_content file.",
    )
    parser.add_argument(
        "--buzzsumo-only",
        dest="buzzsumo_only",
        default=False,
        required=False,
        action="store_true",
        help="[Optional] Flag indicating only Buzzsumo API will be called on links file.",
    )
    args = parser.parse_args()
    return args.__dict__

dir_path(path_name)

Function to convert CLI argument to created directory.

Parameters:

Name Type Description Default
path_name str

Path to target directory.

required

Returns:

Name Type Description
str str

Path to prepared directory.

Source code in minall/cli/parse_args.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def dir_path(path_name: str) -> str:
    """Function to convert CLI argument to created directory.

    Args:
        path_name (str): Path to target directory.

    Returns:
        str: Path to prepared directory.
    """
    if Path(path_name).is_dir():
        return path_name
    else:
        Path(path_name).mkdir(exist_ok=True)
        [p.mkdir(exist_ok=True) for p in Path(path_name).parents]
        return path_name

file_path(path_name)

Function to convert CLI argument to verified, found file path.

Parameters:

Name Type Description Default
path_name str

Path to data file.

required

Raises:

Type Description
FileNotFoundError

Data file not found at given path.

Returns:

Name Type Description
str str

Verified path to data file.

Source code in minall/cli/parse_args.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def file_path(path_name: str) -> str:
    """Function to convert CLI argument to verified, found file path.

    Args:
        path_name (str): Path to data file.

    Raises:
        FileNotFoundError: Data file not found at given path.

    Returns:
        str: Verified path to data file.
    """
    if Path(path_name).is_file():
        return path_name
    else:
        raise FileNotFoundError(path_name)

has_parent(path_name)

Function to convert CLI argument to file path with created parent directories.

Parameters:

Name Type Description Default
path_name str

Path to out-file.

required

Returns:

Name Type Description
str str

Path to out-file with created parent directories.

Source code in minall/cli/parse_args.py
52
53
54
55
56
57
58
59
60
61
62
def has_parent(path_name: str) -> str:
    """Function to convert CLI argument to file path with created parent directories.

    Args:
        path_name (str): Path to out-file.

    Returns:
        str: Path to out-file with created parent directories.
    """
    [p.mkdir(exist_ok=True) for p in Path(path_name).parents]
    return path_name