<commit_before>package pl.pwr.hiervis;

import java.awt.Toolkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import pl.pwr.hiervis.core.HVConfig;
import pl.pwr.hiervis.core.HVContext;
import pl.pwr.hiervis.ui.VisualizerFrame;
import pl.pwr.hiervis.util.SwingUIUtils;
import pl.pwr.hiervis.util.Utils;


public final class HierarchyVisualizer
{
	private static final Logger log = LogManager.getLogger( HierarchyVisualizer.class );

	public static final String APP_NAME = "Hierarchy Visualizer";

	private static Options options;


	private HierarchyVisualizer()
	{
		// Static class -- disallow instantiation.
		throw new RuntimeException( "Attempted to instantiate a static class: " + getClass().getName() );
	}

	public static void main( String[] args ) throws Exception
	{
		createOptions();

		HVContext context = new HVContext();

		// Check if the program can access its own folder
		if ( new File( "." ).exists() == false ) {
			log.error( "Failed to access current working directory." );
			SwingUIUtils.showErrorDialog(
				"Program was unable to access the current working directory.\n\n" +
					"Make sure that you're not trying to run the program from inside of a zip archive.\n" +
					"Also, instead of double-clicking on hv.jar, try to launch start.bat/start.sh"
			);

			System.exit( 0 );
		}

		context.setConfig( loadConfig() );

		CommandLine cmd = parseArgs( args );

		if ( cmd.hasOption( 'h' ) || cmd.hasOption( "help" ) ) {
			printHelp();
			System.exit( 0 );
		}

		String subtitle = null;
		if ( cmd.hasOption( 's' ) ) {
			subtitle = cmd.getOptionValue( 's' );
		}

		File inputFile = null;
		if ( cmd.hasOption( 'i' ) ) {
			inputFile = new File( cmd.getOptionValue( 'i' ) );

			if ( inputFile.isDirectory() ) {
				throw new IOException( inputFile.getPath() + " must be a path to a file!" );
			}
			if ( !inputFile.exists() ) {
				throw new FileNotFoundException( inputFile.getPath() );
			}
		}

		executeGUI( context, subtitle, inputFile );
	}

	@SuppressWarnings("static-access")
	private static void createOptions()
	{
		Option inputOpt = OptionBuilder
			.withArgName( "file path" )
			.hasArgs( 1 )
			.isRequired( false )
			.withDescription( "path to a *.csv file describing a hierarchy to load on app start" )
			.create( "i" );

		Option subtitleOpt = OptionBuilder
			.withArgName( "name" )
			.hasArgs( 1 )
			.isRequired( false )
			.withDescription( "optional subtitle for frame titles, to help identify them" )
			.create( "s" );

		Option helpOpt = OptionBuilder
			.hasArg( false )
			.isRequired( false )
			.withDescription( "prints this message" )<commit_msg>Added support for file options to -i command line option<commit_after>package pl.pwr.hiervis;

import java.awt.Toolkit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.NoSuchElementException;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import pl.pwr.hiervis.core.HVConfig;
import pl.pwr.hiervis.core.HVContext;
import pl.pwr.hiervis.ui.VisualizerFrame;
import pl.pwr.hiervis.util.SwingUIUtils;
import pl.pwr.hiervis.util.Utils;


public final class HierarchyVisualizer
{
	private static final Logger log = LogManager.getLogger( HierarchyVisualizer.class );

	public static final String APP_NAME = "Hierarchy Visualizer";

	private static Options options;


	private HierarchyVisualizer()
	{
		// Static class -- disallow instantiation.
		throw new RuntimeException( "Attempted to instantiate a static class: " + getClass().getName() );
	}

	public static void main( String[] args ) throws Exception
	{
		createOptions();

		HVContext context = new HVContext();

		// Check if the program can access its own folder
		if ( new File( "." ).exists() == false ) {
			log.error( "Failed to access current working directory." );
			SwingUIUtils.showErrorDialog(
				"Program was unable to access the current working directory.\n\n" +
					"Make sure that you're not trying to run the program from inside of a zip archive.\n" +
					"Also, instead of double-clicking on hv.jar, try to launch start.bat/start.sh"
			);

			System.exit( 0 );
		}

		context.setConfig( loadConfig() );

		CommandLine cmd = parseArgs( args );

		if ( cmd.hasOption( 'h' ) || cmd.hasOption( "help" ) ) {
			printHelp();
			System.exit( 0 );
		}

		String subtitle = null;
		if ( cmd.hasOption( 's' ) ) {
			subtitle = cmd.getOptionValue( 's' );
		}

		File inputFile = null;
		if ( cmd.hasOption( 'i' ) ) {
			List<String> inputOptions = new ArrayList<String>( Arrays.asList( cmd.getOptionValues( 'i' ) ) );
			boolean withTrueClass = inputOptions.remove( "true-class" );
			boolean withInstanceNames = inputOptions.remove( "instance-names" );
			boolean withHeader = inputOptions.remove( "header" );
			boolean fixBreadthGaps = inputOptions.remove( "fix-breadth-gaps" );

			inputFile = new File( inputOptions.get( 0 ) );

			HVConfig cfg = context.getConfig();
			cfg.setTrueClassAttribute( withTrueClass );
			cfg.setInstanceNameAttribute( withInstanceNames );
			cfg.setDataNamesRow( withHeader );
			cfg.setFillBreadthGaps( fixBreadthGaps );

			if ( inputFile.isDirectory() ) {
				throw new IOException( inputFile.getPath() + " must be a path to a file!" );
			}
			if ( !inputFile.exists() ) {
				throw new FileNotFoundException( inputFile.getPath() );
			}
		}

		executeGUI( context, subtitle, inputFile );
	}

	@SuppressWarnings("static-access")
	private static void createOptions()
	{
		Option inputOpt = OptionBuilder
			.withArgName( "file path" )
			.hasOptionalArgs( 4 )
			.hasArgs( 5 )
			.isRequired( false )
			.withDescription( "path to a *.csv file describing a hierarchy to load on app start" )
			.create( "i" );

		Option subtitleOpt = OptionBuilder
			.withArgName( "name" )
			.hasArgs( 1 )
			.isRequired( false )
			.withDescription( "optional subtitle for frame titles, to help identify them" )
			.create( "s" );

		Option helpOpt = OptionBuilder
			.hasArg( false )
			.isRequired( false )
			.withDescription( "prints this message" )
{'fraction_non_alphanumeric': 0.1162882787750792, 'fraction_numerical': 0.002375923970432946, 'mean_word_length': 3.9980211081794197, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '814310', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2374, 'n_words': 629}