1+ // Copyright 2025 Kyle Ebbinga
2+
3+ using System . CommandLine ;
4+ using Parallel . Cli . Utils ;
5+ using Parallel . Core . Database ;
6+ using Parallel . Core . IO . FileSystem ;
7+ using Parallel . Core . Settings ;
8+ using Parallel . Core . Utils ;
9+
10+ namespace Parallel . Cli . Commands
11+ {
12+ public class ConfigCommand : Command
13+ {
14+ private Command addCmd = new ( "add" , "Adds a new profile configuration." ) ;
15+ private Command editCmd = new ( "edit" , "Edits a profile configuration." ) ;
16+ private Command viewCmd = new ( "view" , "Shows the profile configuration." ) ;
17+ private Command setCmd = new ( "set" , "Sets a new profile configuration." ) ;
18+ private Command delCmd = new ( "delete" , "Deletes a profile configuration." ) ;
19+
20+ public ConfigCommand ( ) : base ( "config" , "View or edit the profile configurations." )
21+ {
22+ this . SetHandler ( ( ) =>
23+ {
24+ //ProfileConfig profile = ProfileConfig.Load();
25+ CommandLine . WriteLine ( $ "Current profile: '{ Program . Settings . Profiles . FirstOrDefault ( ) } '") ;
26+ } ) ;
27+
28+ this . AddCommand ( addCmd ) ;
29+ addCmd . SetHandler ( ( ) =>
30+ {
31+ CommandLine . WriteLine ( "Creating new database credentials..." , ConsoleColor . DarkGray ) ;
32+ DatabaseCredentials dbc = new DatabaseCredentials ( ) ;
33+ dbc . Provider = Enum . Parse < DatabaseProvider > ( CommandLine . ReadString ( $ "Provider ({ string . Join ( ", " , Enum . GetNames ( typeof ( DatabaseProvider ) ) ) } )") , true ) ;
34+ if ( dbc . Provider == DatabaseProvider . Local )
35+ {
36+ dbc = DatabaseCredentials . Local ;
37+ }
38+ else
39+ {
40+ dbc . Address = CommandLine . ReadString ( "Address" ) ;
41+ dbc . Username = CommandLine . ReadString ( "Username" ) ;
42+ dbc . Password = CommandLine . ReadPassword ( "Password" ) ;
43+ dbc . Name = CommandLine . ReadString ( "Name" ) ;
44+ }
45+
46+ CommandLine . WriteLine ( "Creating new file system credentials..." , ConsoleColor . DarkGray ) ;
47+ FileSystemCredentials fsc = new FileSystemCredentials ( ) ;
48+ fsc . Service = Enum . Parse < FileService > ( CommandLine . ReadString ( $ "Service ({ string . Join ( ", " , Enum . GetNames ( typeof ( FileService ) ) ) } )") , true ) ;
49+ if ( fsc . Service == FileService . Local )
50+ {
51+ fsc . RootDirectory = CommandLine . ReadString ( "Root" ) ;
52+ }
53+ else if ( fsc . Service == FileService . Cloud )
54+ {
55+ fsc . Address = CommandLine . ReadString ( "Bucket Name" ) ;
56+ fsc . Username = CommandLine . ReadString ( "Access Key" ) ;
57+ fsc . Password = CommandLine . ReadPassword ( "Secret Key" ) ;
58+ }
59+ else
60+ {
61+ fsc . RootDirectory = CommandLine . ReadString ( "Root" ) ;
62+ fsc . Address = CommandLine . ReadString ( "Address" ) ;
63+ fsc . Username = CommandLine . ReadString ( "Username" ) ;
64+ fsc . Password = CommandLine . ReadPassword ( "Password" ) ;
65+ }
66+
67+ fsc . Encrypt = CommandLine . ReadBool ( "Encrypt files? (y/n)" , false ) ;
68+ fsc . EncryptionKey = HashGenerator . GenerateHash ( 32 , true ) ;
69+
70+ string profileName = CommandLine . ReadString ( "Profile Name" ) ;
71+ ProfileConfig profile = new ProfileConfig ( profileName , dbc , fsc ) ;
72+ profile . SaveToFile ( ) ;
73+
74+ CommandLine . WriteLine ( $ "Saved new connection profile: '{ profile . Name } '") ;
75+ } ) ;
76+
77+ this . AddCommand ( setCmd ) ;
78+ setCmd . SetHandler ( ( ) =>
79+ {
80+
81+ } ) ;
82+ }
83+ }
84+ }
0 commit comments