Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions floss/language/cli_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import argparse

logger = logging.getLogger(__name__)


def add_common_args(parser: argparse.ArgumentParser, default_min_length: int):
parser.add_argument("path", help="file or path to analyze")
parser.add_argument(
"-n",
"--minimum-length",
dest="min_length",
type=int,
default=default_min_length,
help="minimum string length",
)

logging_group = parser.add_argument_group("logging arguments")
logging_group.add_argument("-d", "--debug", action="store_true", help="enable debugging output on STDERR")
logging_group.add_argument(
"-q",
"--quiet",
action="store_true",
help="disable all status output except fatal errors",
)


def configure_logging(args: argparse.Namespace):
if args.debug:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)
26 changes: 3 additions & 23 deletions floss/language/go/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from floss.utils import get_static_strings
from floss.results import StaticString, StringEncoding
from floss.language.utils import get_extract_stats
from floss.language.cli_common import add_common_args, configure_logging
from floss.language.go.extract import extract_go_strings

logger = logging.getLogger(__name__)
Expand All @@ -32,31 +33,10 @@

def main():
parser = argparse.ArgumentParser(description="Get Go strings")
parser.add_argument("path", help="file or path to analyze")
parser.add_argument(
"-n",
"--minimum-length",
dest="min_length",
type=int,
default=MIN_STR_LEN,
help="minimum string length",
)
logging_group = parser.add_argument_group("logging arguments")
logging_group.add_argument("-d", "--debug", action="store_true", help="enable debugging output on STDERR")
logging_group.add_argument(
"-q",
"--quiet",
action="store_true",
help="disable all status output except fatal errors",
)
add_common_args(parser, MIN_STR_LEN)
args = parser.parse_args()

if args.debug:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)
configure_logging(args)

try:
pe = pefile.PE(args.path)
Expand Down
26 changes: 3 additions & 23 deletions floss/language/rust/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from floss.strings import extract_ascii_unicode_strings
from floss.language.utils import get_extract_stats
from floss.language.cli_common import add_common_args, configure_logging
from floss.language.rust.extract import extract_rust_strings

logger = logging.getLogger(__name__)
Expand All @@ -32,31 +33,10 @@

def main():
parser = argparse.ArgumentParser(description="Get Rust strings")
parser.add_argument("path", help="file or path to analyze")
parser.add_argument(
"-n",
"--minimum-length",
dest="min_length",
type=int,
default=MIN_STR_LEN,
help="minimum string length",
)
logging_group = parser.add_argument_group("logging arguments")
logging_group.add_argument("-d", "--debug", action="store_true", help="enable debugging output on STDERR")
logging_group.add_argument(
"-q",
"--quiet",
action="store_true",
help="disable all status output except fatal errors",
)
add_common_args(parser, MIN_STR_LEN)
args = parser.parse_args()

if args.debug:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)
configure_logging(args)

try:
pe = pefile.PE(args.path)
Expand Down