@@ -7,7 +7,7 @@ use std::process::Command;
7
7
use std:: str:: FromStr ;
8
8
9
9
use clap:: { App , AppSettings , Arg , SubCommand } ;
10
- use serde:: Deserialize ;
10
+ use serde:: { Deserialize , Serialize } ;
11
11
12
12
extern crate toml;
13
13
@@ -417,12 +417,15 @@ impl FromStr for CliCommand {
417
417
#[ derive( Debug , PartialEq ) ]
418
418
pub struct CliArgs {
419
419
pub command : CliCommand ,
420
+ // TODO: `project_name` is currently overloaded and also used as the config
421
+ // path. We should either make this more explicit or introduce separate
422
+ // args.
420
423
pub project_name : String ,
421
424
}
422
425
423
- #[ derive( Clone , Copy , Debug , Deserialize ) ]
426
+ #[ derive( Clone , Copy , Debug , Deserialize , Serialize ) ]
424
427
#[ serde( rename_all = "kebab-case" ) ]
425
- enum Layout {
428
+ pub enum Layout {
426
429
EvenHorizontal ,
427
430
EvenVertical ,
428
431
MainHorizontal ,
@@ -440,23 +443,23 @@ impl fmt::Display for Layout {
440
443
441
444
type StartDirectory = Option < String > ;
442
445
443
- #[ derive( Debug , Default , Deserialize ) ]
444
- struct Pane {
445
- commands : Vec < String > ,
446
- name : Option < String > ,
447
- start_directory : StartDirectory ,
446
+ #[ derive( Debug , Default , Deserialize , Serialize ) ]
447
+ pub struct Pane {
448
+ pub commands : Vec < String > ,
449
+ pub name : Option < String > ,
450
+ pub start_directory : StartDirectory ,
448
451
}
449
452
450
- #[ derive( Debug , Default , Deserialize ) ]
451
- struct Window {
452
- layout : Option < Layout > ,
453
- name : Option < String > ,
453
+ #[ derive( Debug , Default , Deserialize , Serialize ) ]
454
+ pub struct Window {
455
+ pub layout : Option < Layout > ,
456
+ pub name : Option < String > ,
454
457
#[ serde( default ) ]
455
- panes : Vec < Pane > ,
456
- start_directory : StartDirectory ,
458
+ pub panes : Vec < Pane > ,
459
+ pub start_directory : StartDirectory ,
457
460
}
458
461
459
- #[ derive( Debug , Deserialize ) ]
462
+ #[ derive( Debug , Deserialize , Serialize ) ]
460
463
#[ serde( rename_all = "kebab-case" ) ]
461
464
enum HookName {
462
465
// TODO: Does this make sense? If not, document exclusion.
@@ -530,29 +533,29 @@ impl fmt::Display for HookName {
530
533
}
531
534
}
532
535
533
- #[ derive( Debug , Deserialize ) ]
534
- struct Hook {
536
+ #[ derive( Debug , Deserialize , Serialize ) ]
537
+ pub struct Hook {
535
538
command : String ,
536
539
name : HookName ,
537
540
}
538
541
539
- #[ derive( Debug , Deserialize ) ]
542
+ #[ derive( Debug , Deserialize , Serialize ) ]
540
543
pub struct Config {
541
- pane_name_user_option : Option < String > ,
544
+ pub pane_name_user_option : Option < String > ,
542
545
#[ serde( default ) ]
543
- hooks : Vec < Hook > ,
544
- layout : Option < Layout > ,
545
- name : String ,
546
- start_directory : StartDirectory ,
546
+ pub hooks : Vec < Hook > ,
547
+ pub layout : Option < Layout > ,
548
+ pub name : String ,
549
+ pub start_directory : StartDirectory ,
547
550
#[ serde( default ) ]
548
- windows : Vec < Window > ,
551
+ pub windows : Vec < Window > ,
549
552
}
550
553
551
554
impl Config {
552
- pub fn new ( cli_args : & CliArgs ) -> Result < Config , String > {
555
+ pub fn new_from_file_path ( config_path : & String ) -> Result < Config , String > {
553
556
// Need to return String in failure case because toml::from_str may
554
557
// return a toml::de::Error.
555
- let mut config_file = match File :: open ( & cli_args . project_name ) {
558
+ let mut config_file = match File :: open ( & config_path ) {
556
559
Ok ( file) => file,
557
560
Err ( _) => return Err ( String :: from ( "Unable to open config file." ) ) ,
558
561
} ;
0 commit comments