Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56332060
main.rs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
main.rs
View Options
use
std
::
env
;
use
clap
::{
Args
,
Parser
};
use
crate
::
commands
::
import
::
import
;
use
crate
::
commands
::
promote
::
promote
;
mod
commands
;
mod
db
;
mod
fantoir
;
#[derive(Debug, Parser)]
#[command(name =
"fantoir-datasource"
)]
#[clap(author=
"Nasqueron project"
, version, about=
"Import FANTOIR database into PostgreSQL"
, long_about=None)]
enum
FantoirCommand
{
/// Import from FANTOIR file generated by the DGFIP
#[command(arg_required_else_help = true)]
Import
(
ImportArgs
),
/// Promote an imported FANTOIR table as the current FANTOIR table to use
#[command(arg_required_else_help = true)]
Promote
(
PromoteArgs
),
}
#[derive(Debug, Args)]
pub
struct
ImportArgs
{
/// Create table if it doesn't exist
#[arg(short = 'c')]
create_table
:
bool
,
/// Truncate table if it already exists, allowing the overwrite mode.
/// If not specified, the script will fail if table exists.
#[arg(short = 't')]
overwrite_table
:
bool
,
/// The FANTOIR file to import
fantoir_file
:
String
,
/// The name of the table to populate
fantoir_table
:
String
,
}
#[derive(Debug, Args)]
pub
struct
PromoteArgs
{
/// The name of the table to promote
fantoir_table
:
String
,
}
#[tokio::main]
async
fn
main
()
{
let
command
=
FantoirCommand
::
parse
();
// Will exit if argument is missing or --help/--version provided.
let
database_url
=
env
::
var
(
"DATABASE_URL"
)
.
expect
(
"The environment variable DATABASE_URL need to be set to your PostgreSQL database."
);
match
command
{
FantoirCommand
::
Import
(
args
)
=>
{
import
(
&
args
,
&
database_url
).
await
;
},
FantoirCommand
::
Promote
(
args
)
=>
{
promote
(
&
args
.
fantoir_table
,
&
database_url
).
await
;
},
};
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, Nov 7, 03:16 (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4251471
Default Alt Text
main.rs (1 KB)
Attached To
Mode
rDS Nasqueron Datasources
Attached
Detach File
Event Timeline
Log In to Comment