MCPcopy Create free account
hub / github.com/HzaCode/OneCite / process_command

Function process_command

onecite/cli.py:118–208  ·  view source on GitHub ↗

Run the ``onecite process`` subcommand. Args: args: Parsed command-line arguments from :func:`create_parser`. Returns: Exit code — ``0`` on success, ``1`` on failure.

(args: "argparse.Namespace")

Source from the content-addressed store, hash-verified

116
117
118def process_command(args: "argparse.Namespace") -> int:
119 """Run the ``onecite process`` subcommand.
120
121 Args:
122 args: Parsed command-line arguments from
123 :func:`create_parser`.
124
125 Returns:
126 Exit code — ``0`` on success, ``1`` on failure.
127 """
128 try:
129 if args.input_file == '-':
130 input_content = sys.stdin.read()
131 elif os.path.exists(args.input_file):
132 with open(args.input_file, 'r', encoding='utf-8') as f:
133 input_content = f.read()
134 if args.input_type == 'txt' and args.input_file.lower().endswith('.bib'):
135 args.input_type = 'bib'
136 else:
137 input_content = args.input_file
138
139 def interactive_callback(candidates: List[Dict]) -> int:
140 if not args.interactive:
141 # Non-interactive mode, skip all candidates
142 return -1
143
144 print("Found multiple possible matches:")
145 for i, candidate in enumerate(candidates):
146 print(f"{i + 1}. {candidate.get('title', 'Unknown')}")
147 print(f" Authors: {', '.join(candidate.get('authors', []))}")
148 print(f" Journal: {candidate.get('journal', 'Unknown')}")
149 print(f" Year: {candidate.get('year', 'Unknown')}")
150 print(f" Match Score: {candidate.get('match_score', 0)}")
151 print()
152
153 while True:
154 try:
155 choice = input("Please select (1-{}, 0=skip): ".format(len(candidates)))
156 choice_num = int(choice)
157 if choice_num == 0:
158 return -1 # Skip
159 elif 1 <= choice_num <= len(candidates):
160 return choice_num - 1
161 else:
162 print("Invalid selection, please try again")
163 except (ValueError, KeyboardInterrupt):
164 print("Operation cancelled")
165 return -1
166
167 if args.quiet:
168 import logging
169 logging.basicConfig(level=logging.CRITICAL)
170 for logger_name in ['onecite', 'scholarly', 'httpx', 'fake_useragent']:
171 logging.getLogger(logger_name).setLevel(logging.CRITICAL)
172
173 result = process_references(
174 input_content=input_content,
175 input_type=args.input_type,

Callers 1

mainFunction · 0.85

Calls 1

process_referencesFunction · 0.85

Tested by

no test coverage detected