11use std:: {
2- env:: { args, var} ,
3- fs:: { canonicalize, create_dir_all, File } ,
2+ fs:: File ,
43 io:: { stdout, Write } ,
5- os:: unix:: fs:: symlink,
6- path:: PathBuf ,
74 process:: exit,
85} ;
96
107use clap:: Clap ;
11- use color_eyre:: {
12- eyre:: { eyre, Context } ,
13- Result ,
14- } ;
15- use dirs:: home_dir;
8+ use color_eyre:: Result ;
9+ use serde_yaml:: { from_reader, to_string} ;
10+
1611use kustomize_sops:: {
17- cli:: Arguments , cli:: SubCommand , decryption:: decrypt_file, maps :: generate_data_field ,
18- maps:: generate_output_map, types:: Input , types:: Kind , API_VERSION , CONFIG_MAP_OUTPUT ,
19- SECRET_OUTPUT , XDG_CONFIG_HOME ,
12+ cli:: Arguments , cli:: SubCommand , decryption:: decrypt_file, installer ,
13+ maps:: generate_data_field , maps :: generate_output_map, types:: Input , types:: Kind ,
14+ CONFIG_MAP_OUTPUT , SECRET_OUTPUT ,
2015} ;
21- use serde_yaml:: { from_reader, to_string} ;
2216
2317fn main ( ) -> Result < ( ) > {
2418 color_eyre:: install ( ) ?;
@@ -33,7 +27,7 @@ fn main() -> Result<()> {
3327 } ;
3428 }
3529 match arguments. subcommand {
36- Some ( SubCommand :: Install ) => return install ( ) ,
30+ Some ( SubCommand :: Install ) => return installer :: install ( ) ,
3731 None => {
3832 eprintln ! ( "The yaml file is required if no command is set" ) ;
3933 exit ( 1 ) ;
@@ -61,45 +55,3 @@ fn process_simple_decrypt(input: &Input) -> Result<()> {
6155
6256 Ok ( ( ) )
6357}
64-
65- fn install ( ) -> Result < ( ) > {
66- let home = home_dir ( ) . ok_or_else ( || eyre ! ( "Failed to determine home director" ) ) ?;
67- let install_directory = var ( XDG_CONFIG_HOME )
68- . wrap_err ( "failed to get the install directory" )
69- . map ( |config| PathBuf :: from ( config) )
70- . unwrap_or_else ( |_| home. join ( ".config" ) )
71- . join ( "kustomize" )
72- . join ( "plugin" )
73- . join ( API_VERSION ) ;
74-
75- let source = PathBuf :: from ( args ( ) . next ( ) . unwrap ( ) ) ;
76- let source =
77- canonicalize ( & source) . wrap_err ( "failed to find the absolute path of the current binary" ) ?;
78-
79- let kinds = [
80- Kind :: ConfigMapGenerator ,
81- Kind :: SecretGenerator ,
82- Kind :: SimpleDecrypt ,
83- ] ;
84-
85- for kind in & kinds {
86- let kind = format ! ( "{:?}" , kind) ;
87- let destination_folder = install_directory. join ( & kind. to_lowercase ( ) ) ;
88- create_dir_all ( & destination_folder) . wrap_err_with ( || {
89- format ! (
90- "failed to create directory {}" ,
91- & destination_folder. to_string_lossy( )
92- )
93- } ) ?;
94- let destination = destination_folder. join ( & kind) ;
95- println ! (
96- "Linking kustomize-sops-rs to {}" ,
97- & destination. to_string_lossy( )
98- ) ;
99- if !destination. exists ( ) {
100- // XXX: To implement on windows this needs to change
101- symlink ( & source, destination) . wrap_err ( "failed to create link" ) ?;
102- }
103- }
104- Ok ( ( ) )
105- }
0 commit comments